Target object serialization method, device, electronic device and storage medium
By generating transformation protocols and functions to automatically serialize target objects, the problems of low serialization efficiency and high labor cost of JSON are solved, and an efficient serialization process is achieved.
Patent Information
- Application Number
- CN202011251443.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-09
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2040-11-09
AI Technical Summary
In the prior art, JSON serialization consumes a lot of labor costs and is inefficient. Developers need to identify a large number of data types and perform specific serialization operations.
By obtaining the target object to be serialized, a conversion protocol is generated based on its structural information, a conversion function is generated based on the data types of keywords and keyword values in the conversion protocol, and finally a conversion function is used to serialize the target object.
The automated execution process of target object serialization is realized, saving labor costs and improving serialization efficiency.
Smart Images

Figure CN112433787B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for serializing a target object. Background Art
[0002] JSON (JavaScript Object Notation) is a lightweight data exchange format. It is based on a subset of the JavaScript (Standard ECMA-2623rd Edition-December1999) scripting language. JSON uses a text format that is completely independent of the language, but also uses conventions similar to the C language family (including C, C++, C#, Java, JavaScript, Perl, Python, etc.). These features make JSON an ideal data exchange language. It is easy to read and write, and also easy for machines to parse and generate. Serialization is the process of converting the state information of an object into a form that can be stored or transmitted.
[0003] In the related art, when serializing JSON, due to the strong dynamics of JS, developers need to identify a large number of data types, such as string types, array types, etc., and developers also need to perform specific serialization operations for different data types. Therefore, the existing JSON serialization consumes a lot of manpower costs and the efficiency of JSON serialization is low. Summary of the invention
[0004] The present disclosure provides a method, device, electronic device and storage medium for serializing a target object, so as to at least solve the problem that JSON serialization in the related art consumes a lot of manpower costs and has low efficiency. The technical solution of the present disclosure is as follows:
[0005] According to a first aspect of an embodiment of the present disclosure, a method for serializing a target object is provided, comprising: obtaining a target object to be serialized; generating a conversion protocol according to structural information of the target object; generating a conversion function according to keywords in the conversion protocol and data types of values of the keywords; and performing serialization on the target object according to the conversion function.
[0006] Optionally, generating the conversion protocol according to the structural information of the target object includes: generating the conversion protocol according to the keywords in the target object, the data type of the values of the keywords in the target object, and the position information of the keywords in the target object and the values of the keywords in the target object in the target object.
[0007] Optionally, the conversion protocol is generated based on the keywords in the target object, the data types of the values of the keywords in the target object, and the position information of the keywords in the target object and the values of the keywords in the target object in the target object, including: combining the data types of the keywords in the target object and the values of the keywords in the target object into the conversion protocol according to the keywords in the target object and the position information of the values of the keywords in the target object in the target object.
[0008] Optionally, generating a conversion function according to the data type of the keyword and the keyword value in the conversion protocol includes: setting corresponding key-value conversion functions for the keyword and the keyword value, respectively; and splicing the key-value conversion functions into the conversion function according to the position information of the keyword and the keyword value in the conversion protocol.
[0009] Optionally, serializing the target object according to the conversion function includes: adding a preset first symbol to both sides of the keyword according to the key-value conversion function corresponding to the keyword.
[0010] Optionally, serializing the target object according to the conversion function includes: when the data type of the keyword value is a preset first-category data type, keeping the keyword value unchanged according to the key-value conversion function corresponding to the keyword value; the first-category data type includes string type, numeric type, array type, Boolean type and null type.
[0011] Optionally, serializing the target object according to the conversion function includes: when the data type of the keyword value is a preset second type of data type, adding the first symbol on both sides of the keyword contained in the keyword value according to the key-value conversion function corresponding to the keyword value, and keeping the keyword value contained in the keyword value unchanged; the second type of data type includes an object type.
[0012] According to a second aspect of an embodiment of the present disclosure, a target object serialization device is provided, comprising: an acquisition module, configured to acquire a target object to be serialized; a protocol generation module, configured to generate a conversion protocol according to structural information of the target object; a function generation module, configured to generate a conversion function according to keywords in the conversion protocol and data types of values of the keywords; and an execution module, configured to perform serialization on the target object according to the conversion function.
[0013] Optionally, the protocol generation module is configured to generate the conversion protocol based on the keywords in the target object, the data type of the keyword values in the target object, and the position information of the keywords in the target object and the keyword values in the target object.
[0014] Optionally, the protocol generation module is configured to combine the data types of the keywords in the target object and the values of the keywords in the target object into the conversion protocol according to the position information of the keywords in the target object and the values of the keywords in the target object in the target object.
[0015] Optionally, the function generation module includes: a tool setting module, configured to set corresponding key-value conversion functions for the keywords and the values of the keywords, respectively; and a tool splicing module, configured to splice the key-value conversion functions into the conversion function according to the position information of the keywords and the values of the keywords in the conversion protocol.
[0016] Optionally, the execution module is configured to add a preset first symbol to both sides of the keyword according to the key-value conversion function corresponding to the keyword.
[0017] Optionally, the execution module is configured to keep the value of the keyword unchanged when the data type of the value of the keyword is a preset first type of data type, according to the key-value conversion function corresponding to the value of the keyword; the first type of data type includes string type, numeric type, array type, Boolean type and empty type.
[0018] Optionally, the execution module is configured to, when the data type of the value of the keyword is a preset second type of data type, add the first symbol to both sides of the keyword contained in the value of the keyword according to the key-value conversion function corresponding to the value of the keyword, and keep the value of the keyword contained in the value of the keyword unchanged; the second type of data type includes an object type. According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the target object serialization method as described in the first aspect.
[0019] According to a fourth aspect of an embodiment of the present disclosure, a storage medium is provided. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the target object serialization method as described in the first aspect.
[0020] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, including a readable program code, wherein the readable program code can be executed by a processor of an electronic device to complete the target object serialization method described in the first aspect above.
[0021] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:
[0022] The target object serialization scheme provided by the embodiment of the present disclosure generates a conversion protocol according to the structural information of the target object to be serialized, then generates a conversion function according to the data types of the keywords and the values of the keywords in the conversion protocol, and finally, serializes the target object using the conversion function.
[0023] The embodiments of the present disclosure first generate a conversion protocol according to the structural information of the target object. The conversion protocol includes the keywords of the target object and the data types of the keyword values, thereby avoiding the need for developers to identify the keywords of the target object and the data types of the keyword values, saving manpower costs. Furthermore, a conversion function is generated according to the conversion protocol, and the target object is serialized using the conversion function, thereby realizing the automated execution process of the target object serialization and improving the efficiency of the target object serialization.
[0024] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0026] Figure 1 The present invention is a flowchart of a method for serializing a target object according to an exemplary embodiment.
[0027] Figure 2 The present invention is a block diagram of a device for serializing a target object according to an exemplary embodiment.
[0028] Figure 3 The present invention is a block diagram of a serialization electronic device for a target object according to an exemplary embodiment.
[0029] Figure 4 The invention is a block diagram of an electronic device for serializing a target object according to an exemplary embodiment. DETAILED DESCRIPTION
[0030] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0031] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0032] Figure 1 is a flowchart of a method for serializing a target object according to an exemplary embodiment. Figure 1 As shown, the serialization method of the target object may specifically include the following steps.
[0033] In step S11, a target object to be serialized is obtained.
[0034] In the embodiments of the present disclosure, the target object may be a mapping of entities such as people, things, and objects existing in the objective world in computer logic. The target object may include a JSON string, an Extensible Markup Language (XML) string, etc. The embodiments of the present disclosure are described by taking the target object as a JSON string as an example.
[0035] In step S12, a conversion protocol is generated according to the structural information of the target object.
[0036] In the embodiments of the present disclosure, a JSON string may include a keyword and a keyword value, and a JSON string may include more than one keyword and keyword value. The keyword, the keyword value, and the position information of the keyword and the keyword value in the JSON string may be used together as the structural information of the JSON string.
[0037] In an embodiment of the present disclosure, the conversion protocol generated according to the structural information of the JSON string may include keywords in the JSON string, data types of keyword values, and position information of the keywords and keyword values in the JSON string.
[0038] In step S13, a conversion function is generated according to the data types of the keywords and the values of the keywords in the conversion protocol.
[0039] In an embodiment of the present disclosure, after the conversion protocol is generated in the above step S12, a conversion function for serializing the JSON string is generated using the conversion protocol.
[0040] In step S14, serialization is performed on the target object according to the conversion function.
[0041] In an embodiment of the present disclosure, after the conversion function is generated in the above step S13, the conversion function is used to convert the keywords and the values of the keywords in the JSON string, so as to achieve serialization of the JSON string.
[0042] The target object serialization scheme provided by the embodiment of the present disclosure generates a conversion protocol according to the structural information of the target object to be serialized, then generates a conversion function according to the data types of the keywords and the values of the keywords in the conversion protocol, and finally, serializes the target object using the conversion function.
[0043] The embodiments of the present disclosure first generate a conversion protocol according to the structural information of the target object. The conversion protocol includes the keywords of the target object and the data types of the keyword values, thereby avoiding the need for developers to identify the keywords of the target object and the data types of the keyword values, saving manpower costs. Furthermore, a conversion function is generated according to the conversion protocol, and the target object is serialized using the conversion function, thereby realizing the automated execution process of the target object serialization and improving the efficiency of the target object serialization.
[0044] In an exemplary embodiment of the present disclosure, the target object is taken as a JSON string [{name:'jack',age:12,info:{city:'beijing'}}] for example. In the JSON string, name, age, and info are all keywords, 'jack' is the value of the keyword name, 12 is the value of the keyword age, and city:'beijing' is the value of the keyword info. It should be emphasized that the value of the keyword info can contain the keyword city and the value of the keyword city 'beijing'.
[0045] During the execution of the above step S12, a conversion protocol scheme can be generated according to the keywords in the target object, the data types of the values of the keywords in the target object, and the location information of the keywords in the target object and the values of the keywords in the target object. Continuing with the above example, the keywords name, age, and info in the JSON string, the data type of the value of the keyword name 'jack' is a string type, the data type of the value of the keyword age 12 is a number type, and the value of the keyword info city:'beijing' is an object type. In actual applications, the keywords in the target object and the data types of the values of the keywords in the target object can be combined into a conversion protocol scheme according to the location information of the keywords in the target object and the values of the keywords in the target object. Continuing with the above example, according to the position information of the keyword name, the value of the keyword name 'jack', the keyword age, the value of the keyword age 12, the keyword info, the value of the keyword info city:'beijing' in the JSON string, the data type String of the keyword name, the data type Number of the keyword age, the value of the keyword age 12, the keyword info, the data type Object of the keyword info value city:'beijing' are combined into a conversion protocol scheme, that is, the conversion protocol scheme is {name:String,age:Number,info:Object}. It should be noted that the "," between adjacent keywords in the JSON string is retained in the conversion protocol scheme, and the "[" and "]" in the JSON string are deleted in the conversion protocol scheme.
[0046] In an exemplary embodiment of the present disclosure, during the execution of the above-mentioned step S13, corresponding key-value conversion functions can be set for the keywords and the values of the keywords in the conversion protocol scheme respectively, and then the key-value conversion functions can be spliced into the conversion function stringfy according to the position information of the keywords and the values of the keywords in the conversion protocol scheme in the conversion protocol scheme.
[0047] In an exemplary embodiment of the present disclosure, during the execution of the above step S14, a preset first symbol may be added to both sides of the keyword according to the key-value conversion function corresponding to the keyword. In practical applications, the key-value conversion function corresponding to the keywords name, age, and info may convert the keywords name, age, and info into "name", "age", and "info", respectively. That is, "" is added to both sides of the keyword according to the key-value conversion function corresponding to the keyword.
[0048] In an exemplary embodiment of the present disclosure, during the execution of the above step S14, when the data type of the keyword value is a preset first-category data type, the first-category data type can be any one of a string type, a numeric type, an array type, a Boolean type, and an empty type. At this time, the value of the keyword can be kept unchanged according to the key-value conversion function corresponding to the value of the keyword. In actual applications, the key-value conversion function corresponding to the value 'jack' of the keyword name can keep the value 'jack' unchanged according to the data type String of the value 'jack', and it is still 'jack'. The key-value conversion function corresponding to the value 12 of the keyword age can keep the value 12 unchanged according to the data type Number of the value 12, and it is still 12.
[0049] In an exemplary embodiment of the present disclosure, during the execution of the above step S14, when the data type of the value of the keyword is a preset second type of data type, the second type of data type may be an object type. At this time, the first symbol may be added to both sides of the keyword contained in the value of the keyword according to the key-value conversion function corresponding to the value of the keyword, and the value of the keyword contained in the value of the keyword may be kept unchanged. In practical applications, the key-value conversion function corresponding to the value city:'beijing' of the keyword info may convert the value city:'beijing' to "city":'beijing' according to the data type Object of the value city:'beijing'. That is, "" is added to both sides of the keyword city, and the value 'beijing' is kept unchanged.
[0050] The JSON string in the embodiments of the present disclosure can be used as the request content in a Hypertext Transfer Protocol (HTTP) request. Therefore, the serialized JSON string can be added to the HTTP request, and then the HTTP request is transmitted. When the HTTP request is received, it is converted into a JSON string through deserialization, thereby realizing the transmission of the JSON string through the HTTP request.
[0051] Figure 2The block diagram of a device for serializing a target object according to an exemplary embodiment is shown. The device may specifically include the following modules.
[0052] An acquisition module 21 is configured to acquire a target object to be serialized;
[0053] A protocol generation module 22, configured to generate a conversion protocol according to the structural information of the target object;
[0054] A function generation module 23, configured to generate a conversion function according to a keyword in the conversion protocol and a data type of a value of the keyword;
[0055] The execution module 24 is configured to perform serialization on the target object according to the conversion function.
[0056] In an exemplary embodiment of the present disclosure, the protocol generation module 22 is configured to generate the conversion protocol based on the keywords in the target object, the data type of the value of the keyword in the target object, and the position information of the keywords in the target object and the value of the keyword in the target object in the target object.
[0057] In an exemplary embodiment of the present disclosure, the protocol generation module 22 is configured to combine the data types of the keywords in the target object and the values of the keywords in the target object into the conversion protocol according to the position information of the keywords in the target object and the values of the keywords in the target object in the target object.
[0058] In an exemplary embodiment of the present disclosure, the function generation module 23 includes:
[0059] A tool setting module is configured to set corresponding key-value conversion functions for the keyword and the value of the keyword respectively;
[0060] The tool splicing module is configured to splice the key-value conversion functions into the conversion function according to the position information of the keyword and the value of the keyword in the conversion protocol.
[0061] In an exemplary embodiment of the present disclosure, the execution module 24 is configured to add a preset first symbol to both sides of the keyword according to the key-value conversion function corresponding to the keyword.
[0062] In an exemplary embodiment of the present disclosure, the execution module 24 is configured to keep the value of the keyword unchanged when the data type of the value of the keyword is a preset first type of data type according to the key-value conversion function corresponding to the value of the keyword; the first type of data type includes string type, numeric type, array type, Boolean type and empty type.
[0063] In an exemplary embodiment of the present disclosure, the execution module 24 is configured to add the first symbol on both sides of the keyword contained in the value of the keyword according to the key-value conversion function corresponding to the value of the keyword when the data type of the value of the keyword is a preset second type of data type; the second type of data type includes an object type.
[0064] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0065] Figure 3 1 is a block diagram of a serialized electronic device 300 of a target object according to an exemplary embodiment. For example, the electronic device 300 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0066] Reference Figure 3 , the electronic device 300 may include one or more of the following components: a processing component 302 , a memory 304 , a power component 306 , a multimedia component 308 , an audio component 310 , an input / output (I / O) interface 312 , a sensor component 314 , and a communication component 316 .
[0067] The processing component 302 generally controls the overall operation of the electronic device 300, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 302 may include one or more processors 320 to execute instructions to complete all or part of the steps of the serialization method of the target object described above. In addition, the processing component 302 may include one or more modules to facilitate the interaction between the processing component 302 and other components. For example, the processing component 302 may include a multimedia module to facilitate the interaction between the multimedia component 308 and the processing component 302.
[0068] The memory 304 is configured to store various types of data to support operations on the electronic device 300. Examples of such data include instructions for any application or method operating on the electronic device 300, contact data, phone book data, messages, images, videos, etc. The memory 304 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0069] The power supply component 306 provides power to the various components of the electronic device 300. The power supply component 306 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 300.
[0070] The multimedia component 308 includes a screen that provides an output interface between the electronic device 300 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 308 includes a front camera and / or a rear camera. When the electronic device 300 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0071] The audio component 310 is configured to output and / or input audio signals. For example, the audio component 310 includes a microphone (MIC), and when the electronic device 300 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 304 or sent via the communication component 316. In some embodiments, the audio component 310 also includes a speaker for outputting audio signals.
[0072] I / O interface 312 provides an interface between processing component 302 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0073] The sensor assembly 314 includes one or more sensors for providing various aspects of status assessment for the electronic device 300. For example, the sensor assembly 314 can detect the open / closed state of the electronic device 300, the relative positioning of components, such as the display and keypad of the electronic device 300, and the sensor assembly 314 can also detect the position change of the electronic device 300 or a component of the electronic device 300, the presence or absence of user contact with the electronic device 300, the orientation or acceleration / deceleration of the electronic device 300, and the temperature change of the electronic device 300. The sensor assembly 314 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 314 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 314 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0074] The communication component 316 is configured to facilitate wired or wireless communication between the electronic device 300 and other devices. The electronic device 300 can access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 316 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 316 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0075] In an exemplary embodiment, the electronic device 300 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to execute the above-mentioned target object serialization method.
[0076] In an exemplary embodiment, a storage medium including instructions is also provided, such as a memory 304 including instructions, and the instructions can be executed by a processor 320 of an electronic device 300 to complete the serialization method of the target object. Optionally, the storage medium can be a non-transitory computer-readable storage medium, for example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0077] In an exemplary embodiment, a computer program product is also provided, the computer program product includes a readable program code, the readable program code can be executed by the processor 320 of the electronic device 300 to complete the serialization method of the target object. Optionally, the program code can be stored in a storage medium of the electronic device 300, the storage medium can be a non-transitory computer-readable storage medium, for example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0078] Figure 4 4 is a block diagram of an electronic device 400 for serializing a target object according to an exemplary embodiment. For example, the electronic device 400 may be provided as a server. Figure 4 , the electronic device 400 includes a processing component 422, which further includes one or more processors, and a memory resource represented by a memory 432 for storing instructions that can be executed by the processing component 422, such as an application. The application stored in the memory 432 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 422 is configured to execute instructions to perform the above-mentioned target object serialization method.
[0079] The electronic device 400 may also include a power supply component 426 configured to perform power management of the electronic device 400, a wired or wireless network interface 450 configured to connect the electronic device 400 to a network, and an input / output (I / O) interface 458. The electronic device 400 may operate based on an operating system stored in the memory 432, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™ or the like.
[0080] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0081] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A method for serializing a target object, characterized in that: include: Get the target object to be serialized; The target object is a string; Generating a conversion protocol according to the structural information of the target object includes: generating the conversion protocol according to the keywords in the target object, the data types of the values of the keywords in the target object, and the position information of the keywords in the target object and the values of the keywords in the target object in the target object; Generating a conversion function according to the data types of the keywords and the values of the keywords in the conversion protocol, including: setting corresponding key-value conversion functions for the keywords and the values of the keywords respectively; splicing the key-value conversion functions into the conversion function according to the position information of the keywords and the values of the keywords in the conversion protocol; Serializing the target object according to the conversion function, and adding the serialized target object to an HTTP request for transmission via the HTTP request; The performing serialization on the target object according to the conversion function comprises: When the data type of the keyword value is a preset second type of data type, a preset first symbol is added to both sides of the keyword according to the key-value conversion function corresponding to the keyword, and the value of the keyword contained in the keyword value is kept unchanged; the second type of data type includes an object type.
2. The method according to claim 1, characterized in that Generating the conversion protocol according to the keywords in the target object, the data type of the keyword value in the target object, and the location information of the keywords in the target object and the keyword value in the target object in the target object includes: According to the position information of the keywords in the target object and the values of the keywords in the target object in the target object, the data types of the keywords in the target object and the values of the keywords in the target object are combined into the conversion protocol.
3. The method according to claim 1, characterized in that The performing serialization on the target object according to the conversion function comprises: When the data type of the keyword value is a preset first type of data type, the keyword value is kept unchanged according to the key-value conversion function corresponding to the keyword value; the first type of data type includes string type, numeric type, array type, Boolean type and empty type.
4. A target object serialization device, characterized in that: include: An acquisition module, configured to acquire a target object to be serialized; The target object is a string; The protocol generation module is configured to generate a conversion protocol according to the structural information of the target object, including: generating the conversion protocol according to the keywords in the target object, the data types of the values of the keywords in the target object, and the position information of the keywords in the target object and the values of the keywords in the target object in the target object; A function generation module is configured to generate a conversion function according to the data types of the keywords and the values of the keywords in the conversion protocol; the function generation module includes: a tool setting module, configured to set corresponding key-value conversion functions for the keywords and the values of the keywords respectively; a tool splicing module, configured to splice the key-value conversion functions into the conversion function according to the position information of the keywords and the values of the keywords in the conversion protocol; An execution module is configured to serialize the target object according to the conversion function, and the serialized target object is used to be added to an HTTP request and transmitted through the HTTP request; and is configured to add a preset first symbol to both sides of the keyword and keep the value of the keyword contained in the keyword value unchanged according to a key-value conversion function corresponding to the keyword when the data type of the keyword value is a preset second type of data type; the second type of data type includes an object type.
5. The device according to claim 4, characterized in that The protocol generation module is configured to combine the data types of the keywords in the target object and the values of the keywords in the target object into the conversion protocol according to the position information of the keywords in the target object and the values of the keywords in the target object in the target object.
6. The device according to claim 4, characterized in that The execution module is configured to keep the value of the keyword unchanged when the data type of the value of the keyword is a preset first type of data type according to the key-value conversion function corresponding to the value of the keyword; the first type of data type includes string type, numeric type, array type, Boolean type and empty type.
7. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the target object serialization method according to any one of claims 1 to 3.
8. A storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the target object serialization method as claimed in any one of claims 1 to 3.
9. A computer program product, characterized in that The invention comprises a readable program code, wherein the readable program code can be executed by a processor of an electronic device to complete the target object serialization method as claimed in any one of claims 1 to 3.
Citation Information
Patent Citations
Data serialization method and device
CN106777292A