CN113138755A - JSON serialization and deserialization optimization method and system - Google Patents

JSON serialization and deserialization optimization method and system Download PDF

Info

Publication number
CN113138755A
CN113138755A CN202110419119.2A CN202110419119A CN113138755A CN 113138755 A CN113138755 A CN 113138755A CN 202110419119 A CN202110419119 A CN 202110419119A CN 113138755 A CN113138755 A CN 113138755A
Authority
CN
China
Prior art keywords
json
attribute
class
serialization
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110419119.2A
Other languages
Chinese (zh)
Inventor
王少白
周武建
侯尧
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
SHANGHAI INNOMOTION Inc
Original Assignee
SHANGHAI INNOMOTION Inc
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by SHANGHAI INNOMOTION Inc filed Critical SHANGHAI INNOMOTION Inc
Priority to CN202110419119.2A priority Critical patent/CN113138755A/en
Publication of CN113138755A publication Critical patent/CN113138755A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)

Abstract

The invention relates to the technical field of JSON serialization and deserialization optimization, and provides a JSON serialization and deserialization optimization method and system, which comprise the following steps: creating a JSON object abstract base class for sequencing and deserializing optimization of JSON, defining a macro definition object in the JSON object abstract base class, wherein the macro definition object comprises creating attributes of various types and realizing analysis functions on the attributes; when deserializing operation is performed on JSON, analyzing JSON data through a JSON analysis library to generate JSON object key value pairs in a key-va l ue format, creating service logic classes containing all attribute members of the JSON data by calling JSON object abstract base classes, and assigning values to each attribute; when the serialization operation is executed on the JSON, the service logic class is called, the specific value of the attribute member is obtained, the JSON object key value pair in the key-va l ue format is formed, the JSON object key value pair is further subjected to the serialization operation through the JSON analysis library, and the serialized JSON data is generated.

Description

JSON serialization and deserialization optimization method and system
Technical Field
The invention relates to the technical field of JSON serialization and deserialization optimization, in particular to a JSON serialization and deserialization optimization method and system.
Background
JSON is a lightweight data exchange format. The method is easy to read and write by human, and is easy to analyze and generate by a machine. The method is widely applied to software development and programming.
Serialization is a method for storing class objects of high-level languages (such as C + +) in a disk in a byte form or performing data transmission in a software programming process. Deserialization, that is, a method of restoring a serialized byte object to a class object. In programming practice, a method of performing serialization and deserialization by using JSON as a data storage format is widely used.
When the JSON is used for serialization operation, each attribute of the class object needs to generate a corresponding JSON character string according to the syntax specification of the JSON, and then the user data of the character string is stored or transmitted. In the deserialization process, the syntax specification of JSON needs to be installed to analyze the character string, create a class object and assign values to each attribute of the object.
Disadvantages of the prior art:
c + + is an object-oriented programming language, and when C + + is used for programming, there are currently many methods for serializing and deserializing C + + objects by JSON, such as several ten related class libraries like JSON cpp, RapidJSON, Parson, and qjson object in QT environment. However, most of these methods can only perform serialization and deserialization between class objects designated by the methods and JSON data formats. For example, JSON in the QT environment is interconverted with JSON strings using classes specified by QjsonObject, QJsonValue, etc., whereas JsonCpp can only translate between JSON strings and Json:: Value objects. These fixed class objects can only read and write attributes in a key-value (key-value) manner, just like a black box, and do not disclose explicit attributes corresponding to data contained in JSON. In the actual programming process, the following problems can exist, and especially, the problems can be particularly shown when complex JSON data with more attributes and multiple JSON object nesting is used:
1. the use is inconvenient, and the programming efficiency is greatly influenced: a programmer cannot visually see which attribute objects which can be accessed exist in JSON data needing to be converted by current business logic in a code editor and the value types of the attributes;
2. not beneficial to multi-person cooperation: in the programming process, the JSON is used for serialization and deserialization so as to exchange data, a JSON data format may be defined by a certain software designer, and a software programmer using the JSON for data exchange may not be the former, so that the programmer has to completely know or easily query the structure and content contained by a JSON data format setter, which may result in a large amount of communication or writing of description documents for query to solve the problem, and the reliability and efficiency of multi-person cooperation are greatly reduced.
3. It is easy to make mistakes, error concealment, error correction is difficult: once the programmer wrongly writes or misses the corresponding attribute in the JSON data, the code editor cannot give an error prompt in the syntax detection stage. When a program runs, errors may not occur, but data stored in a serialized JSON character string is wrong, and deserialization cannot be performed to obtain a correct attribute value, so that a series of service logics for exchanging data with the JSON use wrong data until a certain service logic sensitive to the data is wrong, thereby causing error concealment, being difficult to trace back to a source of the error, and even causing serious adverse effects to the whole system.
Disclosure of Invention
In view of the above problems, the present invention aims to provide a method and a system for optimizing JSON serialization and deserialization, which make a series of key improvements on the basis of the prior art, solve the corresponding problems, and particularly have more obvious advantages for complex JSON data with more attributes and multiple JSON object nesting, wherein the following aspects are mainly embodied:
1. high-efficient convenience: a class is defined for each JSON object in the JSON data, the attribute of the corresponding JSON object is disclosed, and a programmer can visually see the content contained in the corresponding data format. The corresponding business logic can be quickly written through the prompt of the code editor.
2. Multi-person collaboration: software designers defining the JSON data format can quickly design corresponding classes for other programmers to use only by a few simple macro definitions.
3. The mistake is not easy to occur: since the class corresponding to JSON is already used by the programmer, the code editor or compiler can judge the correctness of the business logic when syntax detection is performed, and errors can not occur during operation.
The above object of the present invention is achieved by the following technical solutions:
a JSON serialization and deserialization optimization method comprises the following steps:
creating a JSON object abstract base class for sequencing and deserializing optimization of JSON, and defining macro definition objects which comprise creating attributes of various types and realizing analysis functions on the attributes in the JSON object abstract base class;
when deserializing operation is carried out on JSON, JSON data is analyzed through a JSON analysis library comprising QJSON, JsonCpp, RapidJSON and Parson, JSON object key value pairs in a key-value format are generated, then a service logic class containing all attribute members of the JSON data is created by calling the JSON object abstract base class, and each attribute is assigned;
when the serialization operation is executed on the JSON, the service logic class is called, the specific value of the attribute member is obtained, the key value pair of the JSON object in the key-value format is formed, the JSON object key value pair is further subjected to the serialization operation through the JSON analysis library, and the serialized JSON data is generated.
Further, defining in the JSON object abstraction base class includes creating attributes of each type, and defining a macro definition object for implementing an analysis function on each attribute, which specifically includes:
establishing macro definition objects of various types of attributes, wherein the macro definition objects comprise definition schemes of all common data types including integer type, floating point type, double precision type, Boolean type, character string type, byte type, array and nested Json objects, and directly establishing the existing attribute types in the corresponding JSON data structures by using the macro definition objects in the business logic class;
the macro definition object for realizing the analysis function on each attribute comprises a head and a tail of a common function for initializing each attribute and a macro definition for specifically assigning the attribute.
Further, when deserializing operation is performed on JSON, a service logic class containing all attribute members of the JSON data is created by calling the JSON object abstraction base class, which specifically includes:
taking the JSON object abstract base class as a public class, and inheriting the JSON object abstract base class when the specific business logic class of the JSON data is created;
and after the service logic class inherits the JSON object abstract base class, directly calling all macro definitions contained in the JSON object abstract base class.
Further, an attribute initialization virtual function for initializing an attribute value is included in the JSON object abstract base class, and then the logic of the attribute initialization virtual function is rewritten in the service logic class, so that each attribute of the specific JSON data is assigned in each service logic class.
Further, in the business logic class, the redefinition of the attribute initialization virtual function performs definition of an execution body paragraph by two macro definitions including a start segment for defining execution of an initialization attribute value function and an end segment for defining execution of an initialization attribute value function;
a segment included between the definition execution initialization attribute value function start segment and the definition execution initialization attribute value function end segment is a definition body of the attribute initialization virtual function.
Furthermore, multiple nesting of JSON objects is realized by defining the object through the macro of the defined nested Json objects;
and when creating the attribute member containing the multiple nested JSON objects of the service logic class, assigning the value of the attribute member through the deserialized JSON data defined by other service logic classes.
Further, defining a uniform conversion interface, calling the JSON analysis library to analyze JSON data during deserializing operation to generate JSON object key value pairs in a key-value format, and calling the JSON analysis library to execute serialization operation during serialization operation to generate serialized JSON data.
A system for performing the method of optimizing JSON serialization and deserialization as described above, comprising:
the system comprises an abstract basic class creating module, a macro definition module and a task execution module, wherein the abstract basic class creating module is used for creating a JSON object abstract basic class used for performing serialization and deserialization optimization on JSON, and the definition in the JSON object abstract basic class comprises the creation of attributes of various types and the macro definition of a macro definition object for realizing an analysis function on each attribute;
the de-serialization module is used for analyzing JSON data through a JSON analysis library including QJSON, JsonCpp, RapidJSON and Parson when performing de-serialization operation on JSON, generating JSON object key value pairs in a key-value format, creating service logic classes containing all attribute members of the JSON data by calling the JSON object abstract base class, and assigning values to each attribute;
and the serialization module is used for calling the service logic class when the JSON is subjected to serialization operation, acquiring the specific value of the attribute member, forming the JSON object key value pair in a key-value format, further performing the serialization operation on the JSON object key value pair through the JSON analysis library, and generating the serialized JSON data.
A computer device comprising a memory and one or more processors, the memory having stored therein computer code that, when executed by the one or more processors, causes the one or more processors to perform the visual UI style design method described above.
A computer-readable storage medium storing computer code which, when executed, causes the above-described visual UI style design method to be performed.
Compared with the prior art, the invention has at least one of the following beneficial effects:
(1) the JSON serialization and deserialization optimization method comprises the following steps: creating a JSON object abstract base class for sequencing and deserializing optimization of JSON, and defining macro definition objects which comprise creating attributes of various types and realizing analysis functions on the attributes in the JSON object abstract base class; when deserializing operation is carried out on JSON, JSON data is analyzed through a JSON analysis library comprising QJSON, JsonCpp, RapidJSON and Parson, JSON object key value pairs in a key-value format are generated, then a service logic class containing all attribute members of the JSON data is created by calling the JSON object abstract base class, and each attribute is assigned; when the serialization operation is executed on the JSON, the service logic class is called, the specific value of the attribute member is obtained, the key value pair of the JSON object in the key-value format is formed, the JSON object key value pair is further subjected to the serialization operation through the JSON analysis library, and the serialized JSON data is generated. According to the technical scheme, an abstract base class for generating the JSON object is predefined, the JSON object in the key-value format generated by conversion through the existing method is further automatically converted into a specific service logic class for storage, and then during programming, a programmer can visually see the content contained in the corresponding data format through the prompt of a code editor, so that rapid programming can be realized. Meanwhile, the method is convenient for multi-person cooperation, and after the class is converted, the code editor can directly judge the correctness of the business logic during grammar detection, so that errors can not occur during operation.
(2) Multiple nesting of JSON objects is realized by defining macro definition objects nested with Json objects in a JSON object abstract base class; and when creating the attribute member containing the multiple nested JSON objects of the service logic class, assigning the value of the attribute member through the deserialized JSON data defined by other service logic classes. The technical scheme can completely convert the JSON object containing multiple nesting into multiple nesting business logic classes which can be recognized by a code editor.
Drawings
FIG. 1 is an overall flow chart of the JSON serialization and deserialization optimization method of the present invention;
FIG. 2 is a flow chart of JSON deserialization according to the present invention;
FIG. 3 is a flow chart of JSON serialization according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and/or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
The main idea of the invention is that under the C + + development environment, the existing JSON analysis library, such as QJsonObject, JsonCpp and the like under QT, is used to complete the operation of bottom JSON serialization or deserialization, on the basis, a layer of logic is packaged, classes corresponding to JSON are defined, and data conversion is carried out on the classes. The invention encapsulates the conversion process and provides a method for creating a corresponding C + + class object, so that JSON data defined by JSON data personnel can be directly mapped into the corresponding C + + class object, thereby achieving the purpose of directly serializing and deserializing between the C + + class and the JSON. The following examples are given to illustrate the present invention.
First embodiment
As shown in fig. 1, the present embodiment provides a JSON serialization and deserialization optimization method, including:
and creating a JSON object abstract base class for sequencing and deserializing optimization of JSON, wherein defining in the JSON object abstract base class comprises creating attributes of various types and defining macro objects for realizing analysis functions of the attributes.
Specifically, a JSON object abstract base class is created, and then aiming at a specific single JSON object, the JSON object in the key-value format is redefined to generate a business logic class aiming at the single JSON object in a mode of inheriting the JSON object abstract base class according to the JSON object abstract base class. When a programmer accesses and calls the JSON object, the programmer does not need to know the specific attributes in the JSON object, all the attributes can be displayed in a grammar prompting mode directly through a code editor, multi-user cooperation is facilitated, and mistakes are not easy to make.
Two types of macro definition objects for creating attributes of various types and realizing analysis functions of the attributes are specifically included in the JSON object abstract basic class.
(1) Creating macro definitions for types of attributes
The macro definition objects for creating various types of attributes comprise definition schemes of all common data types including integer type, floating point type, double precision type, Boolean type, character string type, byte type, array and nested Json objects, and the macro definition objects are directly used in the business logic class to create the existing attribute types in the corresponding JSON data structures. Because these attributes are defined by macro to automatically create the set/get function of the function, these attributes can be used as grammar prompt by the direct code editor during programming and can also be identified by grammar detection, namely can be displayed for use. Examples are listed in table 1 below:
TABLE 1
Figure BDA0003027121310000071
Figure BDA0003027121310000081
Figure BDA0003027121310000091
Wherein WJSON _ PROP _ OBJ (TYPE _ OBJECT, PROP _ NAME) is a macro definition OBJECT of a defined nested Json OBJECT, and realizes multiple nesting of JSON OBJECTs; and when creating the attribute member containing the multiple nested JSON objects of the service logic class, assigning the value of the attribute member through the deserialized JSON data defined by other service logic classes.
(2) Macro definition for implementing parsing function for each attribute
The macro definition object for realizing the analysis function on each attribute comprises a head and a tail of a common function for initializing each attribute and a macro definition for specifically assigning the attribute. When the unified conversion interface acquires corresponding basic data from the basic component, the function defined by the macro is called, so that the purpose of assigning values to all the attributes of the current class is achieved, and the deserialization is realized. These macro definitions include the three macros shown in Table 2 below:
TABLE 2
Figure BDA0003027121310000101
The virtual void initprop () { } is an attribute initialization virtual function for initializing an attribute value, and then logic of the attribute initialization virtual function is rewritten in the business logic classes, so that each attribute of specific JSON data is assigned in each business logic class.
And, in the business logic class, the redefinition of the attribute initialization virtual function performs the definition of the execution body paragraph by two macro definitions including a definition execution initialization attribute value function start segment (INIT _ prop) and a definition execution initialization attribute value function END segment (END _ INIT _ prop); a segment included between the definition execution initialization attribute value function start segment and the definition execution initialization attribute value function end segment is a definition body of the attribute initialization virtual function.
After the JSON object abstract base class is created, the deserialization and serialization operation of the JSON object are executed through the assistance of the JSON object abstract base class. The method specifically comprises the following steps:
(1) deserialization operation
As shown in fig. 2, when deserializing is performed on JSON, JSON data is parsed by a JSON parsing library including QJSON, JSON cp, RapidJSON, and Parson, and a key-value-format JSON object key-value pair is generated, and then a service logic class including all attribute members of the JSON data is created by calling the JSON object abstraction base class, and each attribute is assigned.
When deserializing operation is executed on the JSON, a service logic class containing all attribute members of the JSON data is created by calling the JSON object abstract base class, and the method specifically comprises the following steps: taking the JSON object abstract base class as a public class, and inheriting the JSON object abstract base class when the specific business logic class of the JSON data is created; and after the service logic class inherits the JSON object abstract base class, directly calling all macro definitions contained in the JSON object abstract base class.
The JSON object abstraction base class realizes the virtual function of the _ initProps (), the subclasses rewrite the logic of the function through the second group of macro definitions, the specific responsibility of the subclasses is assigned to each attribute, when the unified conversion interface extracts the analyzed JSON object from the basic component, the _ initProps () function is called, and then the function calls the function of analyzing each attribute value specified by the subclasses in the macro definitions, so that the corresponding attribute value in the JSON data is assigned to each attribute of the subclasses, and the deserialization is realized.
(2) Serialized operations
As shown in fig. 3, when performing a serialization operation on JSON, the service logic class is called, a specific value of an attribute member is obtained, a key-value-format key-value pair of the JSON object is formed, and then the key-value pair of the JSON object is subjected to a serialization operation through the JSON parsing library to generate serialized JSON data.
A subclass attribute assignment function (set function) realized through macro definition directly submits a corresponding value to a conversion interface every time, the conversion interface writes the value into a key value pair type object of a basic component, when serialization is needed, a serialization function provided by the conversion interface is called, and the conversion interface calls a serialization method provided by the basic component to complete serialization operation.
It should be noted that the JSON data is parsed by JSON parsing libraries including QJSON, JSON cpp, RapidJSON, and Parson, and the JSON parsing libraries are existing libraries supporting C + + and JSON conversion and serve as basic components for serialization and deserialization, and the above components are only examples, and may also include any other components with similar functions.
Meanwhile, the unified conversion interface provided by the invention has the following responsibilities: and the module is responsible for calling the method provided by the component to acquire the corresponding basic data type taking the key value pair as a data access mode. The method specifically comprises the following steps:
defining a uniform conversion interface, calling the JSON analysis library to analyze JSON data to generate JSON object key value pairs in a key-value format during deserializing operation, and calling the JSON analysis library to execute serializing operation to generate serialized JSON data during serializing operation.
Second embodiment
This embodiment provides a specific example of using macros to define subclasses corresponding to JSON.
Such as a JSON object with one Student (Student) data, which contains: number (string ID), Name (string Name), gender (bone Sex), Age (int Age). The json data are as follows:
Figure BDA0003027121310000121
a Student class is correspondingly defined, wherein the WJsonObject is a Json object abstract base class provided by the invention, and the definition of the Student class is as follows:
Figure BDA0003027121310000122
Figure BDA0003027121310000131
third embodiment
The present embodiment provides a system for performing an optimization method of JSON serialization and deserialization as in the first embodiment, including:
the system comprises an abstract basic class creating module, a macro definition module and a task execution module, wherein the abstract basic class creating module is used for creating a JSON object abstract basic class used for performing serialization and deserialization optimization on JSON, and the definition in the JSON object abstract basic class comprises the creation of attributes of various types and the macro definition of a macro definition object for realizing an analysis function on each attribute;
the de-serialization module is used for analyzing JSON data through a JSON analysis library including QJSON, JsonCpp, RapidJSON and Parson when performing de-serialization operation on JSON, generating JSON object key value pairs in a key-value format, creating service logic classes containing all attribute members of the JSON data by calling the JSON object abstract base class, and assigning values to each attribute;
and the serialization module is used for calling the service logic class when the JSON is subjected to serialization operation, acquiring the specific value of the attribute member, forming the JSON object key value pair in a key-value format, further performing the serialization operation on the JSON object key value pair through the JSON analysis library, and generating the serialized JSON data.
A computer readable storage medium storing computer code which, when executed, performs the method as described above. Those skilled in the art will appreciate that all or part of the steps in the methods of the above embodiments may be implemented by associated hardware instructed by a program, which may be stored in a computer-readable storage medium, and the storage medium may include: read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disks, and the like.
The above description is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments, and all technical solutions belonging to the idea of the present invention belong to the protection scope of the present invention. It should be noted that modifications and embellishments within the scope of the invention may occur to those skilled in the art without departing from the principle of the invention, and are considered to be within the scope of the invention.
The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
It should be noted that the above embodiments can be freely combined as necessary. The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.

Claims (10)

1. A JSON serialization and deserialization optimization method is characterized by comprising the following steps:
creating a JSON object abstract base class for sequencing and deserializing optimization of JSON, and defining macro definition objects which comprise creating attributes of various types and realizing analysis functions on the attributes in the JSON object abstract base class;
when deserializing operation is carried out on JSON, JSON data is analyzed through a JSON analysis library comprising QJSON, JsonCpp, RapidJSON and Parson, JSON object key value pairs in a key-value format are generated, then a service logic class containing all attribute members of the JSON data is created by calling the JSON object abstract base class, and each attribute is assigned;
when the serialization operation is executed on the JSON, the service logic class is called, the specific value of the attribute member is obtained, the key value pair of the JSON object in the key-value format is formed, the JSON object key value pair is further subjected to the serialization operation through the JSON analysis library, and the serialized JSON data is generated.
2. The method for optimizing JSON serialization and deserialization according to claim 1, wherein defining a macro definition object in the JSON object abstraction base class includes creating attributes of each type and implementing parsing functions for each attribute, and specifically includes:
establishing macro definition objects of various types of attributes, wherein the macro definition objects comprise definition schemes of all common data types including integer type, floating point type, double precision type, Boolean type, character string type, byte type, array and nested Json objects, and directly establishing the existing attribute types in the corresponding JSON data structures by using the macro definition objects in the business logic class;
the macro definition object for realizing the analysis function on each attribute comprises a head and a tail of a common function for initializing each attribute and a macro definition for specifically assigning the attribute.
3. The method for optimizing JSON serialization and deserialization according to claim 1, wherein when deserialization is performed on JSON, a business logic class containing all attribute members of the JSON data is created by calling the JSON object abstraction base, specifically:
taking the JSON object abstract base class as a public class, and inheriting the JSON object abstract base class when the specific business logic class of the JSON data is created;
and after the service logic class inherits the JSON object abstract base class, directly calling all macro definitions contained in the JSON object abstract base class.
4. The method for optimizing JSON serialization and deserialization according to claim 3, further comprising:
and attribute initialization virtual functions for initializing attribute values are contained in the JSON object abstract base class, and then the logic of the attribute initialization virtual functions is rewritten in the service logic class, so that each attribute of the specific JSON data is assigned in each service logic class.
5. The method for optimizing JSON serialization and deserialization according to claim 4, further comprising:
in the business logic class, the redefinition of the attribute initialization virtual function limits an execution body paragraph through two macro definitions including a start segment for defining and executing an initialization attribute value function and an end segment for defining and executing an initialization attribute value function;
a segment included between the definition execution initialization attribute value function start segment and the definition execution initialization attribute value function end segment is a definition body of the attribute initialization virtual function.
6. The method for optimizing JSON serialization and deserialization according to claim 2, further comprising:
multiple nesting of JSON objects is realized by defining the macro definition objects of the nested Json objects;
and when creating the attribute member containing the multiple nested JSON objects of the service logic class, assigning the value of the attribute member through the deserialized JSON data defined by other service logic classes.
7. The method for optimizing JSON serialization and deserialization according to claim 1, further comprising:
defining a uniform conversion interface, calling the JSON analysis library to analyze JSON data to generate JSON object key value pairs in a key-value format during deserializing operation, and calling the JSON analysis library to execute serializing operation to generate serialized JSON data during serializing operation.
8. A system for performing the method of optimization of JSON serialization and deserialization of claims 1-7, comprising:
the system comprises an abstract basic class creating module, a macro definition module and a task execution module, wherein the abstract basic class creating module is used for creating a JSON object abstract basic class used for performing serialization and deserialization optimization on JSON, and the definition in the JSON object abstract basic class comprises the creation of attributes of various types and the macro definition of a macro definition object for realizing an analysis function on each attribute;
the de-serialization module is used for analyzing JSON data through a JSON analysis library including QJSON, JsonCpp, RapidJSON and Parson when performing de-serialization operation on JSON, generating JSON object key value pairs in a key-value format, creating service logic classes containing all attribute members of the JSON data by calling the JSON object abstract base class, and assigning values to each attribute;
and the serialization module is used for calling the service logic class when the JSON is subjected to serialization operation, acquiring the specific value of the attribute member, forming the JSON object key value pair in a key-value format, further performing the serialization operation on the JSON object key value pair through the JSON analysis library, and generating the serialized JSON data.
9. A computer device comprising memory and one or more processors, the memory having stored therein computer code that, when executed by the one or more processors, causes the one or more processors to perform the method of any of claims 1-7.
10. A computer readable storage medium storing computer code which, when executed, performs the method of any of claims 1 to 7.
CN202110419119.2A 2021-04-19 2021-04-19 JSON serialization and deserialization optimization method and system Pending CN113138755A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110419119.2A CN113138755A (en) 2021-04-19 2021-04-19 JSON serialization and deserialization optimization method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110419119.2A CN113138755A (en) 2021-04-19 2021-04-19 JSON serialization and deserialization optimization method and system

Publications (1)

Publication Number Publication Date
CN113138755A true CN113138755A (en) 2021-07-20

Family

ID=76812723

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110419119.2A Pending CN113138755A (en) 2021-04-19 2021-04-19 JSON serialization and deserialization optimization method and system

Country Status (1)

Country Link
CN (1) CN113138755A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114117992A (en) * 2021-11-25 2022-03-01 北京力控元通科技有限公司 Serialization and deserialization method and device and electronic equipment
CN115237415A (en) * 2022-09-22 2022-10-25 南京雷电信息技术有限公司 Method for realizing situation duplication under GIS platform

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016029788A1 (en) * 2014-08-29 2016-03-03 优视科技有限公司 Serialization method and apparatus and deserialization method and apparatus
CN105573956A (en) * 2015-12-10 2016-05-11 盛趣信息技术(上海)有限公司 Serialization method and serialization-based network communication method
CN112286594A (en) * 2020-10-10 2021-01-29 百度(中国)有限公司 Object serialization and deserialization method and device, electronic device and medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016029788A1 (en) * 2014-08-29 2016-03-03 优视科技有限公司 Serialization method and apparatus and deserialization method and apparatus
CN105573956A (en) * 2015-12-10 2016-05-11 盛趣信息技术(上海)有限公司 Serialization method and serialization-based network communication method
CN112286594A (en) * 2020-10-10 2021-01-29 百度(中国)有限公司 Object serialization and deserialization method and device, electronic device and medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
大蓝头: "C++对象的JSON序列化与反序列化探索完结-列表的序列化与反序列化", pages 1 - 14, Retrieved from the Internet <URL:https://blog.csdn.net/tragicguy/article/details/9174015> *
徐步小兵: "【C/C++业务】cJSON总结与使用", pages 1 - 13, Retrieved from the Internet <URL:https://blog.csdn.net/weixin_43166958/article/details/114287183> *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114117992A (en) * 2021-11-25 2022-03-01 北京力控元通科技有限公司 Serialization and deserialization method and device and electronic equipment
CN115237415A (en) * 2022-09-22 2022-10-25 南京雷电信息技术有限公司 Method for realizing situation duplication under GIS platform
CN115237415B (en) * 2022-09-22 2022-12-16 南京雷电信息技术有限公司 Method for realizing situation duplication under GIS platform

Similar Documents

Publication Publication Date Title
US5850550A (en) No preprocessor and a source level debugger for embedded SQL in a 3GL
CN106462425B (en) Method and system for using complex constants
US7610545B2 (en) Annotations for tracking provenance
US9043759B1 (en) System and method for generating software unit tests simultaneously with API documentation
CN107861728B (en) Method and system for converting traditional program language into modern program language
JP5851396B2 (en) Processing method
US9280442B1 (en) System and method for generating coverage reports for software unit tests
US10140119B2 (en) Modular serialization
US8752020B2 (en) System and process for debugging object-oriented programming code leveraging runtime metadata
US10853096B2 (en) Container-based language runtime loading an isolated method
US20120151437A1 (en) Method for translating a cobol source program into readable and maintainable program code in an object oriented second programming language
US20080270979A1 (en) Methods and systems for using type models to generate an implementation of a type
Grimmer et al. Cross-language interoperability in a multi-language runtime
US7512938B2 (en) Typed intermediate representation for object-oriented languages
US9910591B2 (en) Visualizations of memory layouts in software programs
KR101770292B1 (en) Computer-executable model reverse engineering method and apparatus performing the same
CN113138755A (en) JSON serialization and deserialization optimization method and system
Córdoba-Sánchez et al. Ann: A domain-specific language for the effective design and validation of Java annotations
RU2347269C2 (en) System and method of declarative definition and use of subclasses in marking
WO2022172025A1 (en) Optimising computer program code
US10275154B2 (en) Building memory layouts in software programs
US10983771B1 (en) Quality checking inferred types in a set of code
US9552192B2 (en) Context-based generation of memory layouts in software programs
CN111475150A (en) Cross-language binding method, device, equipment and storage medium
Brewer et al. Thirty Years Is Long Enough: Getting Beyond C.

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination