C + + parsing code generation method and system based on JSON data, and medium
Through the method of parsing HTTP server data and traversing graphs, C++ code adapted to different data sources and complex business logic is generated, which solves the problem of insufficient flexibility in code generation in the existing technology, and realizes more efficient development and compilation period detection.
Patent Information
- Application Number
- CN202510629629.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-16
- Publication Date
- 2025-06-13
- Estimated Expiration
- 2045-05-16
AI Technical Summary
The existing technology lacks flexible configuration for different data sources, and the generated C/C++ code is only suitable for specific JSON data structures and cannot meet the needs of complex business logic.
By reading HTTP server data, creating a JSON dataset and parsing the dataset, using the visitor mode to traverse the graph, check type conflicts, dynamic nodes, and generate C++ code.
It realizes flexible configuration of different data sources, and the generated C++ code can adapt to multiple data sources and complex needs, improves development efficiency and supports the detection of JSON file format changes during the compilation period.
Smart Images

Figure CN120144103A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software engineering. Specifically, it relates to a method, system and medium for generating C++ parsing code based on JSON data. Background Art
[0002] Referring to the code generation method for converting a general JSON object into a C / C++ structured object disclosed in CN112114793A, first, scan the data structure definition of the structured object to obtain the logical structure metadata information tree of the structured object; then, perform a depth-first traversal of the metadata information tree; then, according to the traversed node type, create output simple assignment, nested assignment, and array loop assignment codes for non-array leaf nodes, non-array non-leaf nodes, and array nodes respectively; finally, merge the generated codes and output them to a file for development use.
[0003] However, in the prior art, there is a lack of flexible configuration for different data sources, and the special configurations required for processing different data sources (such as HTTP server interfaces and local files) are not considered. In practical applications, different data sources have different structures and interaction methods.
[0004] In addition, the flexibility of the generated code is insufficient, and a flexible configuration method for multiple data sources and different requirements is not provided. The generated C / C++ code is only applicable to specific JSON data structures, lacks the ability to be customized, and cannot meet the requirements of complex business logic. Summary of the Invention
[0005] The purpose of the present invention is to provide a method, system and medium for generating C++ parsing code based on JSON data to solve the above problems in the prior art.
[0006] The present invention is achieved through the following technical solutions: In a first aspect, a method for generating C++ parsing code based on JSON data provided by the present invention includes: Read the data of the HTTP server, create a JSON data set to obtain UrlEntry, and parse the JSON data set; For each UrlEntry, create a graph Graph, the nodes of the graph correspond to the keys of the JSON, and create a list including the attributes of the nodes, and the list is used to store the type corresponding to the key; Traverse each graph using the visitor pattern through TypeVisitor, start checking from the first node whether there are conflicts in all types stored in the node. If there are conflicts, report an error and stop traversing. If there are no conflicts, generate the type corresponding to the node until all nodes are traversed; Use the visitor pattern through MergeVisitor to traverse each graph. Starting from the first node, check whether the node is a dynamic node. If the node is dynamic, mark the node as Merged. If the node is not a dynamic node, do not mark it until all nodes are traversed; Use the visitor pattern through CodeVisitor to traverse each graph. Starting from the first node, check whether the node is Merged. If it is, skip it. If not, generate a C++ class for the node, and the class members are the children nodes of the node until all nodes are traversed, generate the C++ code for parsing all the collected Json data sets, store it in a file and output.
[0007] Preferably, the creation of the JSON data set to obtain UrlEntry includes: Store each return result JsonText of the same interface of the HTTP server as an entry, and store it in a unified collection JsonCollection; Store JsonCollection and several access parameters as a UrlEntry, and store it in the data set UrlCollection as an entry of the data set.
[0008] Preferably, the parsing of the JSON data set includes: Traverse each entry UrlEntry in the data set UrlCollection, and then traverse the JsonCollection in each entry UrlEntry. For each JsonText, use JSON syntax to parse it to obtain the corresponding data object JsonObject.
[0009] Preferably, the checking whether there are conflicts in all types stored in the node includes: Judge whether the type of the current node is null. If so, there is no conflict in the type stored in the node; If the type of the current node is not null, there is a conflict in the type stored in the node.
[0010] Preferably, the checking whether the node is a dynamic node includes: Sort all the child nodes of the node by name, traverse the names and types of all the child nodes, and use the obtained string as the structural feature of the node; If the structural feature of the node is the same as that of one of its parent nodes, the node is a dynamic node. Otherwise, the node is not a dynamic node.
[0011] Second aspect, the present invention also provides a C++ parsing code generation system based on JSON data, including: An HTTP server, configured to collect JSON sample data; A Json collector, configured to grab a response file from an external server according to a preset configuration and create data according to the interface format of the Json data set; A Json data set module, configured to save the sample data structure of all interactions and responses of the server; A file collector, configured to create a Json data set according to a JSON file; A CPP code generation module, configured to generate a CPP code file for accessing the collected Json data set according to the collected Json data set.
[0012] Preferably, the Json collector includes: A CollectionCreator module, configured to create a Json data set and add the response text obtained by the HTTP client to the Json collector; An HTTP client, configured to interact with the HTTP server.
[0013] Preferably, the Json data set module includes: A UrlCollection module, configured as a Map container to store all UrlEntries; A UrlEntry module, configured to store all sample access data of a certain URL; A Url module, configured to access a certain URL; A JsonCollection module, configured as a List container to store all sample access data of a certain URL; A JsonText module, configured as a certain sample access data in string format; An Option module, configured to set configuration options used when generating parsing code for a URL.
[0014] Preferably, the CPP code generation module includes: A JsonReader module, configured to parse a JSON file and generate a corresponding JsonObject; A JsonObject module, configured as a memory representation of the tree structure of a JSON file; A JsonNode module, configured as a node of the JsonObject tree structure, corresponding to an attribute node in the JSON file; The GraphCreator module is configured to convert a JsonObject into a graph structure Graph; The Graph module is configured to represent a JsonObject, and one Graph corresponds to one JsonObject; The Vertex module is configured to represent the vertices of the graph structure, and one vertex corresponds to one JsonNode; The Edge module is configured to represent the parent-child relationship between Vertices; The TypeCollection module is configured to save the DataType types collected for the same attribute in different sample data; The DataType module is configured to save the types of JSON attributes; The TypeVisitor module is configured to traverse the Graph vertices, analyze the TypeCollection collected for each vertex, and determine whether there are type conflicts within the TypeCollection; The MergeVisitor module is configured to traverse the Graph vertices, make decisions based on the dynamic node configurations of the Option for each vertex, including checking whether the node is a dynamic node. If the node is dynamic, mark the node as Merged; if the node is not a dynamic node, do not mark it; The CodeVisitor module is configured to traverse the Graph vertices and generate CPP code based on the name, type, and whether it is a Merge of each vertex.
[0015] In a third aspect, the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the above-mentioned method for generating C++ parsing code based on JSON data.
[0016] The technical solution of the present invention has at least the following advantages and beneficial effects: 1. By adopting the method for automatically generating code for converting a general JSON object based on a tree into a C / C++ structured object provided by the present invention, which mainly includes automatically generating code for converting a JSON object into a C / C++ structured object according to the data structure definition, it solves the problem of converting a JSON object into a C / C++ structured object without manual coding, thereby improving the development efficiency.
[0017] 2. By generating parsing code, the traditional way of accessing JSON attributes through strings is changed to accessing through functions. In this way, attributes can be selected through the automatic code hint of the IDE without having to memorize strings.
[0018] 3. Detecting JSON file format changes during compilation. In the traditional approach of accessing via string names, when the JSON file format changes, such as a change in an attribute name, it can only be detected at runtime that the attribute name does not exist. By accessing through the generated parsing code, when the JSON file format changes, such as a change in an attribute name, since each attribute name is accessed through a function with the same name, the compiler will prompt that the function does not exist.
[0019] 4. Support for JSON fusion. For the same interface of the server, some attributes may be optional, either because the data is incomplete or for other design reasons such as saving communication data volume, and only partial JSON information is returned each time. By putting different returned information into a JsonCollection, complete C++ access code can be generated. Brief Description of the Drawings
[0020] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as limiting the scope. For those of ordinary skill in the art, without creative efforts, other related drawings can also be obtained based on these drawings.
[0021] Figure 1 It is a schematic diagram of the software control logic of the present invention; Figure 2 It is a schematic diagram of the process for generating C++ parsing code for the HTTP server JSON interface of the present invention; Figure 3 It is a schematic diagram of code hint of the present invention. Detailed Embodiments
[0022] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. Usually, the components of the embodiments of the present invention described and illustrated in the drawings here can be arranged and designed in various different configurations.
[0023] The division of modules in this application is a logical division. In actual implementation, there may be other division methods. For example, multiple modules can be combined or integrated into another system, or some features can be ignored or not executed.
[0024] In addition, the connection, coupling, or communication in this application can be a direct connection, coupling, or communication between associated objects, or an indirect connection, coupling, or communication through other devices. Moreover, the connection, coupling, or communication between objects can be electrical or other similar forms, which are not limited in this application.
[0025] The independently described modules or sub-modules can be physically separated or not: they can be implemented in software or in hardware, and some modules or sub-modules can be implemented in software and the functions of these modules or sub-modules are called by a processor, while other parts of the modules or sub-modules are implemented in hardware, for example, through a hardware circuit. In addition, some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this application.
[0026] JSON (JavaScript Object Notation) is a lightweight data interchange format. It is based on a subset of JavaScript and represents data objects in a text format that is easy for humans to read and write, and is also easy for machines to parse and generate. It is widely used in modern web applications and data interactions.
[0027] Schema is a tool for describing the JSON data structure. It can help verify whether JSON data conforms to the expected format. It constrains JSON data by defining rules such as the type, necessity, and allowable value range of attributes.
[0028] Parsing: Parsing refers to the process of converting JSON-formatted data (usually a string) into a data structure (such as an object, an array, etc.) that can be understood and processed by a programming language. This process allows a program to read the information in the JSON data, such as obtaining specific key-value pairs and traversing array elements.
[0029] C++: C++ is a statically typed, compiled, general-purpose, case-sensitive, and irregular programming language that supports procedural programming, object-oriented programming, and generic programming. It was developed by Bjarne Stroustrup at Bell Labs in the early 1980s as an extension of the C language, aiming to provide more powerful programming capabilities and better code organization. C++ is widely used in system software, game development, embedded systems, high-performance computing, and other fields.
[0030] Please refer to Figure 1 - Figure 2 , a method for generating C++ parsing code based on JSON data provided by the present invention. In this embodiment, it includes two ways of generating parsing code and sending them to the user. One is to generate C++ parsing code for the JSON interface of an HTTP server, including: Configure interface information: mainly configure the URL address, parameters of the external server to be collected, and set whether it is a dynamic node; Collect sample data: According to the URL and access parameters in the configured interface information, call the interfaces of the external server one by one, record the server responses, and create a Json data set.
[0031] Generate code: Generate CPP code based on the sample data and configuration.
[0032] The specific process is as follows: S101: Read the data of the HTTP server, create a JSON data set to obtain UrlEntry, and parse the JSON data set; Access a certain interface of the data server through the HTTP client. The access method is determined by the predefined configuration, including the interface address (Url), interface parameters, and whether it is a dynamic interface (Option). The same interface may have multiple configurations, and each access will be performed according to one configuration. Therefore, an interface may have multiple access results.
[0033] S102: For each UrlEntry, create a graph Graph. The nodes of the graph correspond to the keys of the JSON, and create a list including the attributes of the nodes. The list is used to store the type corresponding to the key; Among them, the types include int, string, bool, null, object, list. The edges of the graph represent the inclusion relationship between the keys. Then add all the JsonObjects under the UrlEntry to the graph according to the above corresponding relationship. According to the detail level returned by the server response, each JsonObject may correspond to all or part of the nodes of the graph.
[0034] S103: Use the visitor pattern to traverse each graph through TypeVisitor. Start from the first node and check whether there are conflicts in all the types stored in the node. If there are conflicts, report an error and stop traversing. If there are no conflicts, generate the type corresponding to the node until all nodes are traversed; S104: Use the visitor pattern to traverse each graph through MergeVisitor. Start from the first node and check whether the node is a dynamic node. If the node is dynamic, mark the node as Merged. If the node is not a dynamic node, do not mark it until all nodes are traversed; S105: Use the visitor pattern through CodeVisitor to traverse each graph. Starting from the first node, check if the node is Merged. If it is, skip it; if not, generate a C++ class for the node, with the class members being the children nodes of the node, until all nodes are traversed, generating C++ code to parse all the collected Json data sets, storing and outputting it in file form.
[0035] Another is to generate parsing code for local JSON files. Generating C++ parsing code for local JSON files is mainly used when the server is unavailable or the interaction is complex (such as requiring a lot of pre-authentication). Generate interface code based on offline file materials, including: Configuration file information: mainly configure local Json disk files that have been collected by other means or written by oneself, including file path and whether it is a dynamic node; Load sample data: Load local files according to the configured file information and create a Json data set. Generate code: Generate CPP code based on the sample data and configuration.
[0036] The specific process includes: Create a JSON data set: Put all local JSON files with the same JSON structure or a sub-structure of a certain same structure into the same folder. Each folder is equivalent to a server interface, and the content JsonText (in JSON format) of each file is stored as an entry for collection in JsonCollection; The subsequent steps are the same as steps S102, S103, S104, and S105.
[0037] Adopting the code automatic generation method provided by the present invention for converting a general JSON object based on a tree into a C / C++ structured object mainly includes automatically generating code for converting a JSON object into a C / C++ structured object according to the data structure definition, solving the problem of converting a JSON object into a C / C++ structured object, without manual coding, and improving development efficiency.
[0038] In an exemplary implementation manner of the present invention, creating a JSON data set to obtain UrlEntry includes: Store each return result JsonText of the same interface of the HTTP server as an entry, and store it in a unified collection JsonCollection; Store JsonCollection and several access parameters as a UrlEntry and store it in the data set UrlCollection as an entry of the data set.
[0039] An exemplary embodiment of the present invention, parsing the JSON data set includes: Traverse each entry UrlEntry in the data set UrlCollection, and then traverse JsonCollection inside each entry. For each JsonText, parse it using JSON syntax to obtain the corresponding data object JsonObject.
[0040] An exemplary embodiment of the present invention, checking whether there are conflicts in all types stored in this node includes: Judge whether the type of the current node is null. If so, there is no conflict in the type stored in this node; if the type of the current node is not null, there is a conflict in the type stored in this node.
[0041] The type generation rule is as follows: if there is only null, it is null; if both null and other types exist, it is other types; if there are only other types except null, it is other types.
[0042] An exemplary embodiment of the present invention, checking whether this node is a dynamic node includes: Sort all child nodes of this node by name, traverse the names and types of all child nodes, and use the obtained string as the structural feature of this node; if the structural feature of this node is the same as that of one of its parent nodes, this node is a dynamic node, otherwise, this node is not a dynamic node.
[0043] In a second aspect, the present invention also provides a C++ parsing code generation system based on JSON data, including: An HTTP server, configured to collect JSON sample data, and the return format of the server interface must be in JSON format; A Json collector, configured to grab a response file from an external server according to a preset configuration and create data according to the interface format of the Json data set; A Json data set module, configured to save the sample data structure of all interaction responses of the server; A file collector, configured to create a Json data set according to a JSON file, where the JSON file is a locally saved or manually written JSON file and will be used to construct the Json data set; A CPP code generation module, configured to generate a CPP code file for accessing the collected Json data set.
[0044] An exemplary embodiment of the present invention, the Json collector includes: The CollectionCreator module is configured to create a Json data set and add the response text obtained by the HTTP client to the Json collector; The HTTP client is configured to interact with the HTTP server, including: GET: The GET request is mainly used to obtain resources from the server; POST: The POST request is mainly used to submit data to the server, usually used to create, update, or delete resources on the server.
[0045] In an exemplary embodiment of the present invention, the Json data set module includes: The UrlCollection module is configured as a Map container to store all UrlEntries; The UrlEntry module is configured to store all sample access data for a certain URL; The Url module is configured to access a certain URL; The JsonCollection module is configured as a List container to store all sample access data for a certain URL; The JsonText module is configured as a certain sample access data in string format; The Option module is configured to set the configuration options used when generating and parsing the URL code.
[0046] In an exemplary embodiment of the present invention, the CPP code generation module includes: The JsonReader module is configured to parse a JSON file and generate a corresponding JsonObject; The JsonObject module is configured as a tree structure memory representation of a JSON file, and one JsonObject corresponds to one JSON file; The JsonNode module is configured as a node of the JsonObject tree structure, corresponding to the attribute node in the JSON file; The GraphCreator module is configured to convert a JsonObject into a graph structure Graph; The Graph module is configured to represent a JsonObject, and one Graph corresponds to one JsonObject; The Vertex module is configured to represent a vertex of the graph structure, and one vertex corresponds to one JsonNode; The Edge module is configured to represent the parent-child relationship between Vertices; The TypeCollection module is configured to save the DataType types collected for the same property in different sample data; The DataType module is configured to save the types of JSON properties; The TypeVisitor module is configured to traverse the Graph vertices, analyze the TypeCollection collected for each vertex, and determine whether there are type conflicts within the TypeCollection; For example, if a vertex collects both int and string types simultaneously, a type conflict will occur, while if a vertex collects both int and null, no conflict will occur. If there is no conflict, an appropriate data type is selected for the vertex; if there is a conflict, an error is reported.
[0047] The MergeVisitor module is configured to traverse the Graph vertices, make decisions based on the dynamic node configurations of the Option for each vertex, including checking whether the node is a dynamic node. If the node is dynamic, the node is marked as Merged; if the node is not a dynamic node, it is not marked; Specifically, if it is a dynamic node, the same-name and same-type child nodes among all the child nodes of the node are marked as Merged. When generating code later, nodes with Merged being true do not generate type code but directly reference the type of the dynamic node. If it is not a dynamic node, it remains unchanged.
[0048] The CodeVisitor module is configured to traverse the Graph vertices, generate CPP code based on the name, type, and whether it is a Merge of each vertex, and finally generate C++ code that can parse all the collected Json data sets in the form of a file.
[0049] The above solution of the present invention can bring the following effects: 1. By generating parsing code, the traditional method of accessing JSON properties through strings is changed to accessing through functions, so that properties can be selected through the automatic code hint of the IDE instead of memorizing strings.
[0050] For example, the following JSON response file: { "timestamp": 1733295008882 "code": 200, "msg": "success", "data": null, } Access as a string: ison data["code"] Access with generated parsing code: ison data.code() like Figure 3 Generate code hints as shown.
[0051] 2. Detect changes in JSON file format during compilation.
[0052] Traditionally, when the JSON file format changes, such as when an attribute name is changed, it can only be detected at runtime that the attribute name does not exist.
[0053] When the JSON file format changes, such as when an attribute name changes, the compiler will prompt that the function does not exist because each attribute name is accessed through a function with the same name.
[0054] 3.Support JSON fusion.
[0055] The same interface of the server may have some optional properties, or only return part of the JSON information each time due to incomplete data or other design reasons such as saving communication data volume. By putting different returned information into a JsonCollection, a complete C++ access code can be generated.
[0056] For example, access getPersonInfo?name=张三, and it will be returned.
[0057] { "name":"Zhang San", "age":18 } Access getPersonInfo?name=Zhang San and return.
[0058] { "name":"Li Si", "height":170 } The merged Json: { "name":"Zhang San", "age":18, "height":170 } 4. Support both static JSON and dynamic JSON.
[0059] Static JSON means that the hierarchy and quantity of the JSON file node structure no longer change.
[0060] For example, { "timestamp": 1733295008882, "code": 200, "msg": "success", "node": { "name": "aa?" } } Dynamic nodes refer to the situation where the quantity and hierarchy of the JSON file nodes may change. For example, there are recursive nodes when representing a tree structure. In the following example, the second-level children is a dynamic node because it can contain third-level, fourth-level, and even infinite-level children: { "timestamp": 1733295008882, "code": 200, "msg": "success", "node": { "name": “aaa", "children": [ { "name": "bbb", "children": [ ] } }
[0061] In addition, in each embodiment of the present invention, each functional unit can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
[0062] When the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods according to the various embodiments of the present invention. The foregoing storage medium includes: various media that can store program codes, such as a USB flash drive, a removable hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc.
[0063] The foregoing are only the preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A C++ parsing code generation method based on JSON data, characterized in that: include: Read HTTP server data, create a JSON data set to get UrlEntry, and parse the JSON data set; For each UrlEntry, create a graph, the nodes of the graph correspond to the keys of the JSON, and create a list including the attributes of the nodes, the list is used to store the type corresponding to the key; Use the visitor mode through TypeVisitor to traverse each graph, starting from the first node, check whether there are conflicts among all types stored in the node. If there are conflicts, report an error and stop traversal. If there are no conflicts, generate the type corresponding to the node until all nodes are traversed. Use the visitor mode through MergeVisitor to traverse each graph, starting from the first node, check whether the node is a dynamic node. If the node is dynamic, mark the node as Merged. If the node is not a dynamic node, do not mark it until all nodes are traversed. Use the visitor mode through CodeVisitor to traverse each graph, starting from the first node, check whether the node is merged, if so, skip it, if not, generate a C++ class for the node, and the class members are the child nodes of the node, until all nodes are traversed, generate C++ code to parse all collected Json data sets, store and output them in the form of files.
2. A C++ parsing code generation method based on JSON data according to claim 1, characterized in that: The creation of a JSON data set to obtain a UrlEntry includes: Store the JSON data returned by each response of the same interface of the HTTP server as independent entries into a unified collection JsonCollection; The JsonCollection and several access parameters are stored as a UrlEntry, and the UrlEntry is stored in the dataset UrlCollection as an entry in the dataset.
3. A C++ parsing code generation method based on JSON data according to claim 2, characterized in that: The parsing of the JSON data set includes: Iterate through each entry UrlEntry in the data set UrlCollection, and then iterate through the JsonCollection in each entry UrlEntry. For each JsonText, parse it using JSON syntax to get the corresponding data object JsonObject.
4. A C++ parsing code generation method based on JSON data according to claim 3, characterized in that: The checking whether all types stored in the node have conflicts includes: Determine whether the type of the current node is null. If so, there is no conflict in the type stored in the node. If the type of the current node is not null, the type stored in the node is conflicting.
5. A C++ parsing code generation method based on JSON data according to claim 4, characterized in that: The checking whether the node is a dynamic node comprises: Sort all the child nodes of the node by name, traverse the names and types of all the child nodes, and use the obtained string as the structural feature of the node; If the structural feature of the node is the same as the structural feature of one of its parent nodes, the node is a dynamic node; otherwise, the node is not a dynamic node.
6. A C++ parsing code generation system based on JSON data, characterized in that: include: HTTP server, configured to collect JSON sample data; The Json collector is configured to fetch response files from an external server according to the preset configuration and create data according to the interface format of the Json data set; The Json dataset module is configured to save the sample data structure of all interactive responses of the server; The file collector is configured to create a Json dataset from a JSON file; The CPP code generation module is configured to generate a CPP code file for accessing the data set according to the collected Json data set.
7. A C++ parsing code generation system based on JSON data according to claim 6, characterized in that: The Json collector includes: The CollectionCreator module is configured to create a Json dataset and add the response text obtained by the HTTP client to the Json collector; HTTP client, configured to interact with HTTP server.
8. A C++ parsing code generation system based on JSON data according to claim 7, characterized in that: The Json dataset module includes: The UrlCollection module is configured as a Map container to store all UrlEntry; The UrlEntry module is configured to store all sample access data for a URL; The Url module is configured to access a URL; The JsonCollection module is configured as a List container to store all sample access data of a certain URL; The JsonText module is configured to access data in a sample string format. The Option module is configured to set the configuration options used when generating the URL parsing code.
9. A C++ parsing code generation system based on JSON data according to claim 8, characterized in that: The CPP code generation module includes: The JsonReader module is configured to parse the JSON file and generate the corresponding JsonObject; The JsonObject module is configured as a tree-structured in-memory representation of a JSON file; The JsonNode module is configured as a node in the JsonObject tree structure, corresponding to the attribute node in the JSON file; The GraphCreator module is configured to convert a JsonObject into a graph structure; The Graph module is configured to represent a JsonObject. One Graph corresponds to one JsonObject. The Vertex module is configured to represent the vertices of the graph structure, and one vertex corresponds to one JsonNode; Edge modules are configured to represent parent-child relationships between Vertexes; The TypeCollection module is configured to save the DataType types collected from different sample data for the same attribute; The DataType module is configured to store the type of the JSON attribute; The TypeVisitor module is configured to traverse the Graph vertices, analyze the TypeCollection collected at each vertex, and determine whether there is a type conflict in the TypeCollection; The MergeVisitor module is configured to traverse the Graph vertices and make decisions based on the dynamic node configuration of each vertex's Option, including checking whether the node is a dynamic node. If the node is dynamic, it marks the node as Merged, and if the node is not a dynamic node, it does not mark it; The CodeVisitor module is configured to traverse the Graph vertices and generate CPP code based on the name, type, and whether it is a Merge for each vertex.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for generating C++ parsing code based on JSON data according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Code generation method and system for converting universal JSON object into C / C++ structured object
CN112114793A
Code generation method, device and equipment and storage medium
CN111414166A
Method, device and system for dynamically constructing model based on Java and readable medium
CN111522545A
Template code generation method and device, computer equipment and storage medium
CN117891453A
Generating Target Schema Based on Source Schema and Query Expression
US20240330571A1