CN117539496A - JSON data analysis packaging method and terminal based on user definition - Google Patents

JSON data analysis packaging method and terminal based on user definition Download PDF

Info

Publication number
CN117539496A
CN117539496A CN202311486903.0A CN202311486903A CN117539496A CN 117539496 A CN117539496 A CN 117539496A CN 202311486903 A CN202311486903 A CN 202311486903A CN 117539496 A CN117539496 A CN 117539496A
Authority
CN
China
Prior art keywords
data
json data
json
analyzed
custom
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
CN202311486903.0A
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.)
Guangdong Baolun Electronics Co ltd
Original Assignee
Guangdong Baolun Electronics Co ltd
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 Guangdong Baolun Electronics Co ltd filed Critical Guangdong Baolun Electronics Co ltd
Priority to CN202311486903.0A priority Critical patent/CN117539496A/en
Publication of CN117539496A publication Critical patent/CN117539496A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention discloses a JSON data analysis packaging method and a processing terminal based on user definition, wherein the method comprises the following steps: constructing a deconstructing function for analyzing the packaged JSON data based on the custom JSOnParser; receiving JSON data to be analyzed, judging the type of the JSON data to be analyzed, and obtaining corresponding data in the JSON data to be analyzed according to the corresponding type; analyzing the obtained corresponding data until a corresponding value is obtained for each key value, wherein the value is operable, and the analysis is completed; and for the data to be packaged, adopting a custom structure STJsonBase to package the data to be packaged. The invention relies on the analysis library of the third party, has simpler operation, keeps higher performance level, consumes shorter time, has better compatibility, is friendly to new hands and has low learning cost.

Description

JSON data analysis packaging method and terminal based on user definition
Technical Field
The invention relates to the technical field of JSON data processing, in particular to a JSON data analysis and encapsulation method based on user definition and a terminal.
Background
JSON is a lightweight data exchange format with the feature of simplicity and legibility, and can conveniently transfer data from one application to another. Because JSON has these obvious advantages, JSON is widely used, and JSON data is adopted in many scenes where data communication is required. For example, the server may encode the data into JSON format to form JSON data and send it to the client. The client parses the JSON data to obtain the required information.
In the c++ development language, if JSON data is required to be used, parsing of the JSON data often depends on a professional JSON parsing library. The common JSON parsing library is as follows:
a RapidJSON library is a high-performance C++ JSON parsing library, but the use mode is relatively complex, and the parsing modes of SAX and DOM are required to be familiar. For beginners, the difficulty of getting hands is high, the learning cost is high, and the use is not convenient enough.
The jsonpp library is an open-source C++ JSON parsing library, and can parse JSON character strings into Json:: value objects and operate on the Json: value objects. But its code base is relatively large, compilation time is long, and is not lightweight. In addition, its API is also relatively complex to use.
The nlohmann/JSON library, which is a modern c++ JSON parsing library, is relatively poor in performance, although it is very simple to use, and does not meet some large projects. A scenario with high performance requirements may not be well suited for use.
The boost. PropertyTree library provides a simple interface to parse JSON data. However, its JSON parsing function is relatively simple and is not well suited to handle complex JSON data structures, making it potentially less capable when parsing large JSON data.
In the parsing library for parsing JSON data in the prior art, the above problems exist more or less. In the process of developing software by adopting C++ language, a JSON data analysis and encapsulation method which is relatively simple and has better performance is also hoped.
Disclosure of Invention
Aiming at the defects of the prior art, the invention aims to provide a JSON data analysis and encapsulation method and a terminal based on user definition, which can solve the problems described in the background art.
The technical scheme for realizing the purpose of the invention is as follows: a JSON data analysis packaging method based on user definition is applied to a C++ development language and comprises the following steps:
step 1: constructing a destructor for analyzing the packaged JSON data based on the custom JSOnParser, wherein the destructor at least comprises the following functions:
1. interconversion between the character string and the Object;
2. converting the Array into a character string;
3. acquiring elements in an Array;
4. determining whether a plurality of key values in the Object exist;
5. obtaining elements in the Object;
step 2: receiving JSON data to be analyzed, judging the type of the JSON data to be analyzed, and obtaining corresponding data in the JSON data to be analyzed according to the corresponding type;
step 3: analyzing the obtained corresponding data until a corresponding value is obtained for each key value, wherein the value is operable, and the analysis is completed;
step 4: and for the data to be packaged, adopting a custom structure STJsonBase to package the data to be packaged.
Further, in step 2, after receiving the JSON data to be parsed and before judging the type of the JSON data to be parsed, the method further includes:
judging whether the JSON data to be analyzed is legal or not, if so, continuing processing, and if not, directly ending processing, or ending processing after returning an error code prompt.
Further, in step 2, if the JSON data to be parsed is JSON data of a single character segment, a data value is obtained from the Object in the JSON data to be parsed; if the JSON data to be analyzed is the JSON data containing the Array, acquiring an Object from the Array in the JSON data to be analyzed; if the JSON data to be analyzed is the JSON data containing the elements in the Array, acquiring the elements in the Array.
Further, step 4 is executed in parallel or sequentially in synchronization with any one of steps 1 to 3.
Further, zeroMQ cross-language communication protocol is adopted to transmit JSON data to be parsed and data to be packaged.
A processing terminal, comprising:
a memory for storing program instructions;
and the processor is used for running the program instructions to execute the steps of the real-time tracking method for the head portraits of the characters in the video.
The invention has the beneficial effects that: the invention eliminates the dependence on various analysis libraries to analyze JSON data, utilizes the custom class JsonParser of the C++ development platform to form a destructor, and completes analysis through the destructor. The analysis function can adapt to JSON data of different types, so that the aim of rapid analysis is fulfilled, the analysis library of a third party is not needed, the operation is simpler, the higher performance level is kept, the time consumption is shorter, the compatibility is better, the method is friendly to new workers, and the learning cost is low. For packaging, the required packaging data is packaged by adopting a method of a self-defined structural body STJsonBase, and the operation is simple.
Drawings
FIG. 1 is a schematic flow chart of the present invention;
fig. 2 is a schematic structural diagram of a processing terminal.
Detailed Description
The invention is further described with reference to the accompanying drawings and detailed description below:
as shown in FIG. 1, the JSON data analysis packaging method based on the user definition is applied to a C++ development language and comprises the following steps:
step 1: constructing a destructor for analyzing the packaged JSON data based on the custom JSOnParser, wherein the destructor at least comprises the following functions:
1. the inter-conversion between the character string and the Object, i.e. converting the character string into the Object and converting the Object into the character string;
2. converting the Array into a character string;
3. acquiring elements in an Array;
4. judging whether a plurality of key values in the Object exist or not, wherein if one or more keys exist and do not exist, true is returned;
5. elements in the Object are obtained.
Step 2: and receiving the JSON data to be analyzed, judging whether the JSON data to be analyzed is legal, if so, continuing to process, and if not, directly ending the process, or ending the process after returning an error code prompt.
In this step, the server receives the data sent by the client, and the client sends the packaged time to the server as JSON data to be parsed by the server, so that the server determines whether the JSON data to be parsed is legal. Legal, that is, JSON data that meets the packaging specification, where packaging specification refers to the requirements that are fulfilled by the packaging method according to the present invention.
Step 3: judging the type of the JSON data to be analyzed, and obtaining corresponding data in the JSON data to be analyzed according to the corresponding type. If the JSON data to be analyzed is JSON data of a single character segment, acquiring a data value from an Object in the JSON data to be analyzed; if the JSON data to be analyzed is the JSON data containing the Array, acquiring an Object from the Array in the JSON data to be analyzed; if the JSON data to be analyzed is the JSON data containing the elements in the Array, acquiring the elements in the Array.
Step 4: and analyzing the obtained corresponding data until a corresponding value is obtained for each key value, wherein the value is operable, and the analysis is completed.
Acquiring the element in the Object does not mean that the JSON data is successfully parsed, and if the JSON data to be parsed is parsed into a value corresponding to each key value and the value can be operated, the parsing is successfully calculated.
Step 5: and for the data to be packaged, adopting a custom structure STJsonBase to package the data to be packaged. A plurality of fields matched with the JSON format are defined in the custom structure STJSOnBase, corresponding function functions are called based on the fields, and packaging of data to be packaged and outward sending are completed based on the called function functions.
In this step, editing operations are further included on the encapsulated data, including adding, modifying, and deleting. Adding a function provided based on a custom JSON parsing class, adding a new key value pair into a JSON object, or adding a new element into a JSON array. Modification is accomplished by accessing keys in the JSON object and modifying their values, or by modifying specific elements in the JSON array. Deletion is the removal of specified key-value pairs from JSON objects, or the removal of specific elements from JSON arrays, using functions provided by custom JSON parsing classes.
For example, the relevant core code for addition, modification and deletion is as follows:
objectijsonobj=jsonparser: : getValueInObject < string > ("{" Key1 ":" value1 "," Key2 ":" value2 "}); resolution JSON data
jsonobj.set ("key 3", "value 3"); new key value pair addition/addition
jsonobj.set ("key 1", "new_value"); value of existing key/modification
jsonobj. Remove ("key 2"); fv/delete key value pair
Step 5 and any one of steps 1-4 are synchronously and parallelly executed or sequentially executed, namely, step 5 can be immediately executed when any one of steps 1-4 is executed or a certain node in a certain step is executed, and step 5 can be immediately executed to complete encapsulation only by receiving data to be encapsulated. Of course, after the steps 1 to 4 are executed, a JSON data analysis may be completed and then packaged. The encapsulation of step 5 and the parsing of steps 1-4 are two independent processes.
In an alternative embodiment, zeroMQ cross-language communication protocol is employed to transport JSON data to be parsed and data to be encapsulated.
The invention eliminates the dependence on various analysis libraries to analyze JSON data, utilizes the custom class JsonParser of the C++ development platform to form a destructor, and completes analysis through the destructor. The analysis function can adapt to JSON data of different types, so that the aim of rapid analysis is fulfilled, the analysis library of a third party is not needed, the operation is simpler, the higher performance level is kept, the time consumption is shorter, the compatibility is better, the method is friendly to new workers, and the learning cost is low. For packaging, the required packaging data is packaged by adopting a method of a self-defined structural body STJsonBase, and the operation is simple.
As shown in fig. 2, the present invention further provides a processing terminal 100, which includes:
a memory 101 for storing program instructions;
and the processor 102 is used for running the program instructions to execute the steps of the custom JSON data parsing and packaging method.
The embodiment disclosed in the present specification is merely an illustration of one-sided features of the present invention, and the protection scope of the present invention is not limited to this embodiment, and any other functionally equivalent embodiment falls within the protection scope of the present invention. Various other corresponding changes and modifications will occur to those skilled in the art from the foregoing description and the accompanying drawings, and all such changes and modifications are intended to be included within the scope of the present invention as defined in the appended claims.

Claims (6)

1. A JSON data analysis packaging method based on self definition is characterized by being applied to a C++ development language and comprising the following steps:
step 1: constructing a destructor for analyzing the packaged JSON data based on the custom JSOnParser, wherein the destructor at least comprises the following functions:
1. interconversion between the character string and the Object;
2. converting the Array into a character string;
3. acquiring elements in an Array;
4. determining whether a plurality of key values in the Object exist;
5. obtaining elements in the Object;
step 2: receiving JSON data to be analyzed, judging the type of the JSON data to be analyzed, and obtaining corresponding data in the JSON data to be analyzed according to the corresponding type;
step 3: analyzing the obtained corresponding data until a corresponding value is obtained for each key value, wherein the value is operable, and the analysis is completed;
step 4: and for the data to be packaged, adopting a custom structure STJsonBase to package the data to be packaged.
2. The method for parsing and packaging JSON data based on custom according to claim 1, wherein in step 2, after receiving the JSON data to be parsed and before determining the type of the JSON data to be parsed, the method further comprises:
judging whether the JSON data to be analyzed is legal or not, if so, continuing processing, and if not, directly ending processing, or ending processing after returning an error code prompt.
3. The method for analyzing and packaging JSON data based on user definition according to claim 1, wherein in step 2, if the JSON data to be analyzed is JSON data of a single character segment, a data value is obtained from an Object in the JSON data to be analyzed; if the JSON data to be analyzed is the JSON data containing the Array, acquiring an Object from the Array in the JSON data to be analyzed; if the JSON data to be analyzed is the JSON data containing the elements in the Array, acquiring the elements in the Array.
4. The custom JSON data parsing packaging method according to claim 1, wherein step 4 is executed in parallel or sequentially with any one of steps 1-3.
5. The custom JSON data parsing and packaging method according to claim 1, wherein ZeroMQ cross-language communication protocol is adopted to transmit JSON data to be parsed and data to be packaged.
6. A processing terminal, characterized in that it comprises:
a memory for storing program instructions;
a processor for executing the program instructions to perform the steps of the custom JSON-based data parsing packaging method of any one of claims 1 to 5.
CN202311486903.0A 2023-11-08 2023-11-08 JSON data analysis packaging method and terminal based on user definition Pending CN117539496A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311486903.0A CN117539496A (en) 2023-11-08 2023-11-08 JSON data analysis packaging method and terminal based on user definition

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311486903.0A CN117539496A (en) 2023-11-08 2023-11-08 JSON data analysis packaging method and terminal based on user definition

Publications (1)

Publication Number Publication Date
CN117539496A true CN117539496A (en) 2024-02-09

Family

ID=89787313

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311486903.0A Pending CN117539496A (en) 2023-11-08 2023-11-08 JSON data analysis packaging method and terminal based on user definition

Country Status (1)

Country Link
CN (1) CN117539496A (en)

Similar Documents

Publication Publication Date Title
CN109902274B (en) Method and system for converting json character string into thraft binary stream
CN115169570B (en) Quantum network protocol simulation method and device and electronic equipment
CN107015948B (en) Log information formatting method and system
CN111249736B (en) Code processing method and device
CN109460220A (en) The predefined code generating method of message, device, electronic equipment and storage medium
CN111078555B (en) Test file generation method, system, server and storage medium
EP3803602A1 (en) Automatic intelligent cloud service testing tool
CN110210212A (en) A kind of data processing method, device and relevant device
US7404186B2 (en) Signature serialization
CN108241676A (en) Realize the method and apparatus that data synchronize
CN111324619A (en) Object updating method, device, equipment and storage medium in micro service system
CN110532182A (en) A kind of automated testing method and device of virtual platform
CN114760369A (en) Protocol metadata extraction method, device, equipment and storage medium
CN111240772A (en) Data processing method and device based on block chain and storage medium
CN110941655B (en) Data format conversion method and device
CN111078573A (en) Test message generation method and device
CN111552839B (en) Object conversion method based on XML template
CN112883088B (en) Data processing method, device, equipment and storage medium
CN117539496A (en) JSON data analysis packaging method and terminal based on user definition
CN110633162A (en) Remote call implementation method and device, computer equipment and storage medium
CN114115900B (en) Script compiling method and device and electronic equipment
CN114371982A (en) Simulation test method, device, equipment and readable storage medium
CN113347196A (en) Analysis method and device for analyzing network data, electronic equipment and storage medium
CN107612919B (en) Protocol configuration method and device
CN111401020A (en) Interface loading method and system and computing equipment

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