CN109684607B - JSON data analysis method and device, computer equipment and storage medium - Google Patents

JSON data analysis method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN109684607B
CN109684607B CN201710979911.7A CN201710979911A CN109684607B CN 109684607 B CN109684607 B CN 109684607B CN 201710979911 A CN201710979911 A CN 201710979911A CN 109684607 B CN109684607 B CN 109684607B
Authority
CN
China
Prior art keywords
json
key
array
name
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.)
Active
Application number
CN201710979911.7A
Other languages
Chinese (zh)
Other versions
CN109684607A (en
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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201710979911.7A priority Critical patent/CN109684607B/en
Publication of CN109684607A publication Critical patent/CN109684607A/en
Application granted granted Critical
Publication of CN109684607B publication Critical patent/CN109684607B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/14Tree-structured documents
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/14Tree-structured documents
    • G06F40/146Coding or compression of tree-structured data
    • 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/51Source to source

Abstract

The application relates to a JSON data analysis method, a JSON data analysis device, computer equipment and a storage medium, wherein the method comprises the following steps: acquiring JSON data; analyzing a data structure of JSON data to obtain each JSON object; acquiring key names of the JSON objects and key values corresponding to the key names; converting each JSON object according to the key name to obtain a Java class corresponding to each JSON object and each field name of the Java class, wherein the field name of the Java class corresponds to the key name of the corresponding JSON object; and reflecting the key name in the JSON object to obtain the field value of each field name of the Java class. The method defines the rule of converting JSON data into JavaBean, and the rule is based on the data structure and does not relate to the content related to the application program to be developed, i.e. does not relate to the application program to be developed. Therefore, the JSON data analysis method is not limited in application range, can be applied to development scenes of various application software, and has high reusability.

Description

JSON data analysis method and device, computer equipment and storage medium
Technical Field
The application relates to the technical field of software development, in particular to a JSON data analysis method and device, computer equipment and a storage medium.
Background
JSON (JSON Object tagging) is a lightweight data exchange format. In the development process of an application program (APP), developers need to analyze JSON data and convert the JSON data into Java classes (javabeans) for further processing.
In a traditional parsing scheme, a developer needs to develop a Java class (JavaBean) in advance, and the numbered javabeans are used for parsing JSON data. The developed Java class usually refers to data content related to the application program for the application program being developed.
Therefore, the traditional JSON data analysis method has low multiplexing rate.
Disclosure of Invention
In view of the above, it is necessary to provide a JSON data parsing method, apparatus, computer device, and storage medium for solving the technical problem of low multiplexing rate.
A JSON data analysis method comprises the following steps:
acquiring JSON data;
analyzing the data structure of the JSON data to obtain each JSON object;
acquiring key names of JSON objects and key values corresponding to the key names;
converting each JSON object according to the key name to obtain a Java class corresponding to each JSON object and each field name of the Java class, wherein the field name of the Java class corresponds to the key name of the corresponding JSON object;
and reflecting the key name in the JSON object to obtain the field value of each field name of the Java class.
A JSON data analysis device comprises an acquisition module, an analysis module, a key acquisition module, a conversion module and a reflection module:
the acquisition module is used for acquiring JSON data;
the analysis module is used for analyzing the data structure of the JSON data to obtain each JSON object;
the key acquisition module is used for acquiring key names of the JSON objects and key values corresponding to the key names;
the conversion module is used for converting each JSON object according to the key name to obtain a Java class corresponding to each JSON object and each field name of the Java class, and the field name of the Java class corresponds to the key name of the corresponding JSON object;
and the reflection module is used for reflecting the key name in the JSON object to obtain the field value of each field name of the Java class.
A computer device comprising a memory and a processor, the memory storing a computer program which, when executed by the processor, causes the processor to perform the steps of the method as described above.
A readable storage medium storing a computer program which, when executed by a processor, causes the processor to perform the steps of the method as described above.
The JSON data analysis method defines a rule for converting JSON data into JavaBean, the rule only relates to a JSON structure, namely, each JSON object is obtained by analyzing the data structure of the JSON data, and each JSON object is converted to obtain a Java class. Since the rule is based on a data structure, it does not relate to the content related to the application to be developed, i.e. to the application to be developed. Therefore, the JSON data analysis method is not limited in application range, can be applied to development scenes of various application software, and has high reusability.
Drawings
FIG. 1 is a diagram of an application environment of a JSON data parsing method in an embodiment;
FIG. 2 is a schematic flow chart of a JSON data parsing method in one embodiment;
FIG. 3 is a flowchart of the steps of parsing a JSON data structure and obtaining JSON objects in one embodiment;
FIG. 4 is a flowchart illustrating the steps of parsing an array structure and obtaining a JSON object with child elements as objects in one embodiment;
FIG. 5 is a schematic flow chart illustrating a JSON data parsing method according to an embodiment of the present invention;
FIG. 6 is a block diagram showing the structure of a JSON data parser in one embodiment;
FIG. 7 is a block diagram showing the structure of a JSON data parser in another embodiment;
FIG. 8 is a block diagram of a computer device in one embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
Fig. 1 is an application environment diagram of a JSON data parsing method in an embodiment. Referring to fig. 1, the JSON data parsing method is applied to a JSON data parsing system. The JSON data system includes a terminal 110 and a server 120. The terminal 110 and the server 120 are connected via a network to obtain JSON data transmitted via the network. The terminal 110 may specifically be a desktop terminal or a mobile terminal, and the mobile terminal may specifically be at least one of a mobile phone, a tablet computer, a notebook computer, and the like. The server 120 may be implemented as a stand-alone server or a server cluster composed of a plurality of servers.
As shown in fig. 2, in one embodiment, a JSON data parsing method is provided. The embodiment is mainly illustrated by applying the method to the terminal 110 in fig. 1. Referring to fig. 2, the JSON data analysis method specifically includes the following steps:
s202, JSON data are obtained.
JSON (JSON Object notification, JSON Object tag) is a lightweight data exchange format, and JSON data refers to data in the JSON format received by a terminal, for example, JSON data sent by a server through a network communication module. It is understood that the content and source of JSON data are not limited for different application scenarios.
S204: and analyzing the data structure of the JSON data to obtain each JSON object.
JSON can have two representation structures: object (jsonoobject) and array (jsonoarray). Where the object starts with "{" braces and ends with "}" braces. The middle part is divided into key/value pairs by. The key needs to be a string and the value can be any other data, such as: a string, a numeric value, a boolean value, an object, or null.
The array begins with an "[" square bracket, ends with a "]" square bracket, and the middle part divides the object by a "," in. An array is an ordered collection of sub-elements, the available objects and array structures of which are described below. One index value per sub-element, i.e., a sub-element index.
In this embodiment, the JSON object to be obtained should be a JSON object of a root node in the JSON data and a JSON object of a child element in an array.
S206: and acquiring the key name of each JSON object and the key value corresponding to the key name.
A JSON key/value (i.e., key name/key value) pair is one way to save an object. The key name in the key/value pair combination is written ahead and "wrapped" with a double quote, using a colon-split, followed by a key value. For example, classname: "Ace", where classname is the key name and Ace is the key value. Data types of key values include numeric (Integer), Long Integer (Long), String (String), Boolean (Boolean), floating point (Float), and Double precision floating point (Double).
In this embodiment, a key name of each JSON object, a key value corresponding to the key name, and a data type of the key value are obtained.
Because the key name and the key value have special formats, the data types of the key name, the key value and the key value can be obtained by analyzing the character strings before and after the special format.
Specifically, the key name, the key value corresponding to the key name and the data type of the key value of each JSON object are obtained through character string analysis.
The expression mode of key/value pair of JSON object is utilized to analyze the character string before and after' to obtain key name of JSON object and key value corresponding to the key name, and the data type of the key value is analyzed.
S208: and converting each JSON object according to the key name to obtain a Java class corresponding to each JSON object and each field name of the Java class, wherein the field name of the Java class corresponds to the key name of the corresponding JSON object.
The JavaBean is a Java class, and becomes an object having a certain function or processing a certain service, called bean for short, by encapsulating attributes and methods. Because the Javabean is based on Java language, the Javabean is independent of a platform, and has the advantages of reusability, easy writing and maintenance, applicability to a platform of a Java running environment and unimportant recompilation. Java classes (Java beans) are reusable components written in Java language that expose members attributes of an internal domain by providing a common method that conforms to a consistent design schema to which attribute names conform, and other Java classes can discover and manipulate the attributes of these Java beans through introspection mechanisms.
The Field name (Field) of a Java class is an object of data processing, and the Field name of the Java class corresponds to the key name of a JSON object, i.e., the Field name of the Java class is the key name of the JSON object. The data type of the JAVA field name corresponds to the data type of the key value of the JSON object, namely the attribute of the JAVA field name is consistent with the data type of the key value of the JSON object. In one embodiment, the table of data type correspondence between the field name attribute and the key value is shown in table 1.
TABLE 1 data type correspondence table of attribute of field name and key value
Figure BDA0001439162440000051
And S210, reflecting the key name in the JSON object to obtain the field value of each field name of the Java class.
The field value is the value corresponding to the field name. Since each field name of the Java class corresponds to the key name of the corresponding JSON object, each field name of each Java class is traversed, and the field value of each field name is obtained by reflecting each field name (i.e., key name) in the JSON object, so that the JSON data is analyzed to recover each field and field value in the Java format to obtain the corresponding Java class, and developers can directly develop the Java class by using the analyzed Java class.
The JSON data analysis method defines a rule for converting JSON data into JavaBean, the rule only relates to a JSON structure, namely, each JSON object is obtained by analyzing the data structure of the JSON data, and each JSON object is converted to obtain a Java class. Since the rule is based on a data structure, it does not relate to the content related to the application to be developed, i.e. to the application to be developed. Therefore, the JSON data analysis method is not limited in application range, can be applied to development scenes of various application software, and has high reusability.
Specifically, in an embodiment, a flowchart of a step of parsing a JSON data structure and acquiring JSON objects is shown in fig. 3, where the step includes the following steps S302 to S306:
s302: and identifying the data structure of the JSON data through a special format symbol corresponding to the data structure of the JSON data.
The special format is a unique symbol in the data structure, and the corresponding data structure can be identified based on the special format.
Specifically, a JSON object (JSONObject) is an object wrapped by the symbols of the symbol "{ }", and the data structure is determined to be a Java object by recognizing the symbols of the symbol "{ }".
And the JSON array (JSONARray) is an array wrapped by [ ], and the data structure is determined to be a Java array by recognizing the [ ]symbol.
S304: when the data structure is an object, a JSON object is obtained.
The JSON object here is a root node JSON object, i.e., a JSON object that is not nested in a JSON array.
S306: and when the data structure is an array, analyzing the array structure and acquiring the JSON object with the child element as the object.
The JSON array is an ordered set of sub-elements, each sub-element has an index value (namely subscript), the data structure of the sub-elements can be a JSON object, and the JSON object with the sub-elements as objects can be obtained by analyzing the JSON array. It is understood that the JSON object whose child element is the object obtained should include all JSON objects in the JSON array, i.e., JSON data including all child elements as objects of multiple nestings.
Specifically, a flowchart of a step of parsing an array structure and acquiring a JSON object with a child element as an object is shown in fig. 4, and the step includes the following steps S402 to S406:
s402: the data structure is parsed for the array.
The JSON array can nest a JSON object and a JSON array, namely the data structure of the sub-element can be a JSON object or a JSON array, the JSON object (JSONObject) is an object wrapped by the { } symbol, and the data structure of the sub-element is determined to be a Java object by identifying the { }' symbol. And the JSON array (JSONARray) is an array wrapped by [ ], and the data structure of the sub-elements is determined to be a Java array by recognizing the [ ]symbol. The method for analyzing the array structure is the same as the data structure analysis method of the JSON data, and the data structure of the JSON data is obtained through recognition based on the special format symbols corresponding to the array structure.
S404: the type of the sub-elements of the array is determined.
When the sub-elements of the array are sub-objects, step S406 is executed: and acquiring the JSON object with the child element as the object.
When the sub-element of the array is a sub-array, returning to step S402: and analyzing the array structure aiming at the array.
Namely, when the JSON array is nested with the JSON array, the steps of analyzing the array structure aiming at the array are returned until the array is traversed.
After the JSON objects are obtained through analysis, key names of the JSON objects, key values corresponding to the key names and data types of the key values are obtained, and the JSON objects are converted according to the key names and the data types of the key values, namely, each JSON object corresponds to one Java class. For an array, the conversion process includes the following three cases:
1. the child elements are basic types, that is, the child elements are numeric types (Integer), Long Integer types (Long), String types (String), Boolean types (Boolean), floating point types (Float), Double precision floating point types (Double), and the like, and are forcibly converted according to the data type correspondence table of the attribute of the field name and the key value shown in table 1.
2. And if the child element is an object (JSONObject), converting each JSON object according to the key name and the data type of the key value to obtain a Java class corresponding to each JSON object and each field name of the Java class, wherein the field name of the Java class corresponds to the key name of the corresponding JSON object, and the data type of the field name of the Java class corresponds to the data type of the key value of the JSON object.
3. If the child element is an array (JSONArray), the structure of the child element of the child array is newly analyzed, and the conversion is performed according to the first case and the second case.
When the child element is an array, since the JSONArray in the JSONArray does not have a key value, in order to facilitate conversion, in this embodiment, the key value of the parent array and the index value of the child array are used as the key name of the child data.
Specifically, with continued reference to fig. 4, when the sub-element of the array is a sub-array, step S408 is executed: and obtaining the key name of the child data according to the key value of the corresponding parent array and the index value of the child array. And after step S408, returning to step S402, the array structure is parsed for the array.
In practical applications, the sub-elements of the array may include at least one or more sub-objects, and the sub-objects may not have key names, and the step of converting each JSON object according to the key name in the conversion process to obtain the Java class corresponding to each JSON object and each field name of the Java class includes the following steps S1 to S3:
s1: all the child objects of the array are converted into one Java class.
S2: and determining the key name of each child object without the key value according to the key name of the parent array.
And determining the key names of the child objects without key values according to the key names of the parent array, namely the array corresponding to the last node of the child elements. In a specific embodiment, the key name of a child object that does not have a key value is the key name of its parent array.
S3: and respectively obtaining the field names corresponding to the index values in the Java class according to the key names of the sub-objects and the index values corresponding to the sub-objects.
I.e. each index value has a respective field name, and the field of field names should include all the attributes of the sub-object, i.e. the key name of the sub-object and the index value of the sub-object. In another embodiment, if the child object has other attributes, the field name corresponding to the index value should be included in the child object, so as to avoid the situation that the field value corresponding to the field name cannot be reflected correctly due to missing attributes.
And for the child objects with the key values of the child elements of the array, converting according to the conversion rules of the objects, namely converting each JSON object according to the key names and the data types of the key values to obtain the Java classes corresponding to the JSON objects and the field names of the Java classes, wherein the field names of the Java classes correspond to the key names of the corresponding JSON objects, and the data types of the field names of the Java classes correspond to the data types of the key values of the JSON objects.
The method analyzes the condition without the key name and defines the corresponding key name, thereby avoiding the condition that the field value corresponding to the field name cannot be correctly reflected due to missing the attribute.
In one embodiment, a flow chart of a JSON data parsing method is shown in fig. 5. It should be understood that, although the steps in the flowchart of fig. 5 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least a portion of the steps in fig. 5 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
Specifically, the method comprises the following steps:
s502: and acquiring JSON data.
S504: and identifying the data structure of the JSON data through a special format symbol corresponding to the data structure of the JSON data.
The special format is a unique symbol in the data structure, and the corresponding data structure can be identified based on the special format.
Specifically, a JSON object (JSONObject) is an object wrapped by the symbols of the symbol "{ }", and the data structure is determined to be a Java object by recognizing the symbols of the symbol "{ }".
And the JSON array (JSONARray) is an array wrapped by [ ], and the data structure is determined to be a Java array by recognizing the [ ]symbol.
S506: when the data structure is an object, a JSON object is obtained.
The JSON object here is a root node JSON object, i.e., a JSON object that is not nested in a JSON array.
S508: when the data structure is an array, the array structure is analyzed for the array.
The JSON array can be nested with the JSON object and the JSON array, namely the data structure of the child element can be the JSON object and can also be the JSON array.
S510: the type of the sub-elements of the array is determined. If yes, go to step S512, and if yes, go to step S514.
S512: and acquiring the JSON object with the child element as the object.
S514: and obtaining the key name of the child data according to the key value of the corresponding parent array and the index value of the child array.
After step S514, the process returns to step S508.
After step S512 and step S506, the method further includes the steps of:
s516: and acquiring the key name of each JSON object, the key value corresponding to the key name and the data type of the key value.
Specifically, the key name, the key value corresponding to the key name and the data type of the key value of each JSON object are obtained through character string analysis.
S518: and converting each JSON object according to the key name and the data type of the key value to obtain a Java class corresponding to each JSON object and each field name of the Java class, wherein the field name of the Java class corresponds to the key name of the corresponding JSON object, and the data type of the field name of the Java class corresponds to the data type of the key value of the JSON object.
When the sub-elements of the array include sub-objects without key values, the step of converting each JSON object according to the key name and the data type of the key value to obtain the Java class corresponding to each JSON object and each field name of the Java class includes the following steps S1 to S3:
s1: and converting all the child objects without the key values of the array into a Java class according to the data type of the key values.
S2: and determining the key name of each child object without the key value according to the key name of the parent array.
S3: and respectively obtaining the field names corresponding to the index values in the Java class according to the key names of the sub-objects and the index values corresponding to the sub-objects.
S520: and reflecting the key name in the JSON object to obtain the field value of each field name of the Java class.
In the above embodiment, a rule for converting JSON data into a JavaBean is defined, where the rule only relates to a JSON structure, that is, each JSON object is obtained by parsing a data structure of the JSON data, and each JSON object is converted to obtain a Java class. Since the rule is based on a data structure, it does not relate to the content related to the application to be developed, i.e. to the application to be developed. Therefore, the JSON data analysis method is not limited in application range, can be applied to development scenes of various application software, has high reusability, further improves development efficiency, and provides an API (application programming interface) for a program based on the JSON data analysis method. By calling the API interface, various JSON contents can be automatically analyzed and assigned with the JavaBean, the conversion from any JSON content to the JavaBean is realized, developers can directly use the analyzed JavaBean to develop, and the development efficiency is improved.
In one embodiment, a JSON data parsing apparatus is provided, as shown in fig. 6, and includes an obtaining module 602, a parsing module 604, a key obtaining module 606, a converting module 608, and a reflecting module 610.
An obtaining module 602, configured to obtain JSON data.
And the analysis module 604 is configured to analyze a data structure of the JSON data to obtain each JSON object.
A key obtaining module 606, configured to obtain a key name of each JSON object and a key value corresponding to the key name.
The conversion module 608 is configured to convert each JSON object according to the key name to obtain a Java class corresponding to each JSON object and each field name of the Java class, where the field name of the Java class corresponds to the key name of the corresponding JSON object.
And the reflection module 610 is configured to obtain field values of field names of the Java classes according to reflection of the key names in the JSON objects.
The JSON data analysis device defines a rule for converting JSON data into JavaBean, the rule only relates to a JSON structure, namely, each JSON object is obtained by analyzing the data structure of the JSON data, and each JSON object is converted to obtain a Java class. Since the rule is based on a data structure, it does not relate to the content related to the application to be developed, i.e. to the application to be developed. Therefore, the JSON data analysis method is not limited in application range, can be applied to development scenes of various application software, and has high reusability.
Fig. 7 is a schematic structural diagram of a JSON data parsing apparatus according to another embodiment. As shown in fig. 7, the parsing module 604 includes: the device comprises a data structure acquisition module and an object acquisition module.
The data structure identification module is used for identifying and obtaining the data structure of the JSON data through the special format symbol corresponding to the data structure of the JSON data.
The object acquisition module is used for acquiring a JSON object when the data structure is the object; and when the data structure is an array, analyzing the array structure and acquiring the JSON object with the child element as the object.
In yet another embodiment, the data structure identification module is further configured to parse the array structure for the array, and further configured to parse the array structure for the array when the child element of the array is a child array.
And the object acquisition module is further used for acquiring the JSON object with the sub-element as the object when the sub-element of the array is the sub-object.
In another embodiment, the converting module 608 is further configured to convert all the child objects without key values in the array into a Java class, determine key names of the child objects without key values according to the key names of the parent array, and obtain field names corresponding to the index values in the Java class according to the key names of the child objects and the index values corresponding to the child objects.
In one embodiment, the apparatus according to claim 9, wherein the key obtaining module 606 is further configured to, when the child element of the array is a child array, obtain the key name of the child data according to the key value of the corresponding parent array and the index value of the child array.
In another embodiment, the key obtaining module is further configured to obtain, through character string analysis, a key name and a key value corresponding to the key name of each JSON object.
A computer device comprising a memory and a processor, the memory storing a computer program which, when executed by the processor, causes the processor to perform the steps of the above method.
FIG. 8 is a diagram illustrating an internal structure of a computer device in one embodiment. The computer device may specifically be the terminal 110 in fig. 1. As shown in fig. 8, the computer apparatus includes a processor, a memory, a network interface, an input device, and a display screen connected through a system bus. Wherein the memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system and may also store a computer program that, when executed by a processor, causes the processor to implement a JSON data parsing method. The internal memory may also store a computer program that, when executed by the processor, causes the processor to perform a JSON data parsing method. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
Those skilled in the art will appreciate that the architecture shown in fig. 8 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, the JSON data parsing apparatus provided in the present application may be implemented in the form of a computer program, and the computer program may be run on a computer device as shown in fig. 8. The memory of the computer device may store various program modules constituting the JSON data parsing means, such as the acquisition module, the parsing block, and the conversion module shown in fig. 6. The computer program constituted by the respective program modules causes the processor to execute the steps in the JSON data parsing method of the embodiments of the present application described in the present specification.
For example, the computer device shown in fig. 8 can execute the step of acquiring JSON data through an acquisition module in the JSON data parsing apparatus shown in fig. 6. And the computer equipment can execute the step of converting each JSON object according to the key name through a conversion module to obtain each JSO.
A readable storage medium, storing a computer program which, when executed by a processor, causes the processor to perform the steps of the above-described method.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a non-volatile computer-readable storage medium, and can include the processes of the embodiments of the methods described above when the program is executed. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present application. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (12)

1. A JSON data analysis method comprises the following steps:
acquiring JSON data;
identifying and obtaining a data structure of JSON data through a special format symbol corresponding to the data structure of the JSON data;
when the data structure is an array, analyzing the array structure to obtain a JSON object with a child element as an object;
acquiring key names of JSON objects and key values corresponding to the key names;
converting each JSON object according to the key name to obtain a Java class corresponding to each JSON object and each field name of the Java class, wherein the field name of the Java class corresponds to the key name of the corresponding JSON object; when the sub-elements of the array comprise sub-objects without key names, the step of converting each JSON object according to the key names to obtain the Java classes corresponding to the JSON objects and the field names of the Java classes comprises the following steps: converting all child objects of the array without key names into a Java class; determining the key name of each child object without the key name according to the key name of the parent array; respectively obtaining field names corresponding to all index values in the Java class according to the key names of the sub-objects and the index values corresponding to the sub-objects; the index value is a subscript of a sub-element;
and reflecting the key name in the JSON object to obtain the field value of each field name of the Java class.
2. The method according to claim 1, further comprising, after the identifying the data structure of the JSON data by the special format corresponding to the data structure of the JSON data, the step of: and when the data structure is an object, acquiring a JSON object.
3. The method according to claim 1, wherein the step of parsing the array structure and obtaining the JSON object with the child element as the object comprises:
analyzing an array structure aiming at the array;
when the sub-elements of the array are sub-objects, acquiring JSON objects with the sub-elements as objects;
and returning to the step of analyzing the array structure aiming at the array when the sub-elements of the array are sub-arrays.
4. The method according to claim 3, wherein when the child element of the array is a child array, the key name of the child array is obtained according to the corresponding key value of the parent array and the index value of the child array.
5. The method according to any one of claims 1 to 4, wherein the step of obtaining the key name of each JSON object and the key value corresponding to the key name comprises:
and acquiring the key name of each JSON object and a key value corresponding to the key name through character string analysis.
6. A JSON data analysis device comprises an acquisition module, an analysis module, a key acquisition module, a conversion module and a reflection module:
the acquisition module is used for acquiring JSON data;
the analysis module is used for identifying and obtaining the data structure of the JSON data through a special format symbol corresponding to the data structure of the JSON data; when the data structure is an array, analyzing the array structure to obtain a JSON object with a child element as an object;
the key acquisition module is used for acquiring key names of the JSON objects and key values corresponding to the key names;
the conversion module is used for converting each JSON object according to the key name to obtain a Java class corresponding to each JSON object and each field name of the Java class, and the field name of the Java class corresponds to the key name of the corresponding JSON object; when the sub-elements of the array comprise sub-objects without key names, the conversion module is used for converting all the sub-objects without key names of the array into a Java class; determining the key name of each child object without the key name according to the key name of the parent array; respectively obtaining field names corresponding to all index values in the Java class according to the key names of the sub-objects and the index values corresponding to the sub-objects; the index value is a subscript of a sub-element;
and the reflection module is used for reflecting the key name in the JSON object to obtain the field value of each field name of the Java class.
7. The apparatus of claim 6, wherein the parsing module is configured to obtain a JSON object when the data structure is an object.
8. The apparatus of claim 6, wherein the data structure identification module is further configured to parse an array structure for an array, and further configured to parse the array structure for the array if the child element of the array is a child array;
and the object obtaining module is further configured to obtain, when the child element of the array is a child object, a JSON object whose child element is an object.
9. The apparatus of claim 8, wherein the key obtaining module is further configured to, when a child element of the array is a child array, obtain a key name of the child array according to a corresponding key value of the parent array and an index value of the child array.
10. The apparatus according to any one of claims 6 to 9, wherein the key obtaining module is further configured to obtain, through character string analysis, a key name of each JSON object and a key value corresponding to the key name.
11. A computer device comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the method according to any one of claims 1 to 5.
12. A storage medium storing a computer program which, when executed by a processor, causes the processor to carry out the steps of the method according to any one of claims 1 to 5.
CN201710979911.7A 2017-10-19 2017-10-19 JSON data analysis method and device, computer equipment and storage medium Active CN109684607B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710979911.7A CN109684607B (en) 2017-10-19 2017-10-19 JSON data analysis method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710979911.7A CN109684607B (en) 2017-10-19 2017-10-19 JSON data analysis method and device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN109684607A CN109684607A (en) 2019-04-26
CN109684607B true CN109684607B (en) 2022-04-08

Family

ID=66183822

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710979911.7A Active CN109684607B (en) 2017-10-19 2017-10-19 JSON data analysis method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN109684607B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111107042B (en) * 2018-10-26 2021-03-09 广州汽车集团股份有限公司 Message parsing method and device, computer equipment and storage medium
CN110222008A (en) * 2019-05-06 2019-09-10 平安国际智慧城市科技股份有限公司 A kind of conversion method of data format, system, medium and electronic equipment
CN110554877A (en) * 2019-09-05 2019-12-10 北京博睿宏远数据科技股份有限公司 JSON data analysis method, device, equipment and storage medium
CN111339093A (en) * 2020-02-25 2020-06-26 京东方科技集团股份有限公司 Method, device and equipment for acquiring user behavior data and storage medium
CN112882974B (en) * 2021-02-09 2024-01-05 深圳市云网万店科技有限公司 JSON data conversion method and device, computer equipment and storage medium
CN115567589B (en) * 2022-09-29 2023-06-13 上海顺舟智能科技股份有限公司 Compression transmission method, device and equipment of JSON data and storage medium
CN115586904B (en) * 2022-12-12 2023-04-07 云筑信息科技(成都)有限公司 JSON data format description-based dynamic generation method for Java beans
CN116738252B (en) * 2023-07-12 2024-01-05 上海中汇亿达金融信息技术有限公司 Configuration loading method, device and application based on fuzzy matching
CN116610679B (en) * 2023-07-17 2023-10-17 金锐同创(北京)科技股份有限公司 json data analysis method, json data analysis device, computer equipment and computer medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103455381A (en) * 2012-05-29 2013-12-18 国际商业机器公司 Method and system for de-serializing source object of source software into target software component
CN106598922A (en) * 2016-12-23 2017-04-26 Tcl集团股份有限公司 Character string conversion method and system
CN107220096A (en) * 2017-04-20 2017-09-29 北京小度信息科技有限公司 A kind of json data analysis methods and device

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8533665B2 (en) * 2009-11-16 2013-09-10 Cisco Technology, Inc. Generating object annotations
CN102158482B (en) * 2011-03-10 2013-11-20 易程(苏州)软件股份有限公司 JSON (JavaScript Object Notation) data protocol based passenger transport information communication method and system
CN102508674A (en) * 2011-12-02 2012-06-20 方正国际软件有限公司 Method based on JSON (javascript serialized object notation) for passing object-oriented parameters and system
US9588742B2 (en) * 2013-09-20 2017-03-07 Oracle International Corporation Rule-based automatic class generation from a JSON message
CN105138683B (en) * 2015-09-15 2018-06-15 歌尔股份有限公司 JSON data turn the method and system of two-dimensional array
CN105808262B (en) * 2016-03-11 2018-10-19 浙江工业大学 A kind of name matching process based on json formatted datas
CN105787128B (en) * 2016-03-29 2019-04-23 四川秘无痕信息安全技术有限责任公司 A method of restoring Java and serializes file data
CN106649634A (en) * 2016-12-08 2017-05-10 武汉斗鱼网络科技有限公司 JSON data analysis method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103455381A (en) * 2012-05-29 2013-12-18 国际商业机器公司 Method and system for de-serializing source object of source software into target software component
CN106598922A (en) * 2016-12-23 2017-04-26 Tcl集团股份有限公司 Character string conversion method and system
CN107220096A (en) * 2017-04-20 2017-09-29 北京小度信息科技有限公司 A kind of json data analysis methods and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
代码工具1.自动根据json字符串生成javabean类;般若梦;《https://blog.csdn.net/loveghs/article/details/49149913》;20151015;1-10页 *

Also Published As

Publication number Publication date
CN109684607A (en) 2019-04-26

Similar Documents

Publication Publication Date Title
CN109684607B (en) JSON data analysis method and device, computer equipment and storage medium
US10618137B2 (en) Automated constructing method of cloud manufacturing service and cloud manufacturing system
CN109325009B (en) Log analysis method and device
CN108804159B (en) Javascript module loading method and preprocessing method and device thereof, and computer equipment
CN106022483B (en) The method and apparatus converted between machine learning model
CN109840083B (en) Webpage component template construction method and device, computer equipment and storage medium
CN111680253B (en) Page application data packet generation method and device, computer equipment and storage medium
CN109145235B (en) Method and device for analyzing webpage and electronic equipment
CN109597618B (en) Program development method, program development device, computer device, and storage medium
US20210064453A1 (en) Automated application programming interface (api) specification construction
US20200142674A1 (en) Extracting web api endpoint data from source code
CN110221871B (en) Webpage acquisition method and device, computer equipment and storage medium
CN110365724B (en) Task processing method and device and electronic equipment
CN112187713A (en) Message conversion method, device, computer equipment and storage medium
CN115599359A (en) Code generation method, device, equipment and medium
CN113360300B (en) Interface call link generation method, device, equipment and readable storage medium
CN111240772A (en) Data processing method and device based on block chain and storage medium
CN111158777A (en) Component calling method and device and computer readable storage medium
CN115982491A (en) Page updating method and device, electronic equipment and computer readable storage medium
CN113535160B (en) Method, device, system, electronic device and storage medium for multiplexing application modules
CN115202756A (en) Vue-based component loading method and system and electronic equipment
CN112417020A (en) Method and device for realizing service expansion, computer equipment and storage medium
CN113419740A (en) Program data stream analysis method and device, electronic device and readable storage medium
CN110647568A (en) Method and device for converting graph database data into programming language data
US11960560B1 (en) Methods for analyzing recurring accessibility issues with dynamic web site behavior and devices thereof

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
GR01 Patent grant
GR01 Patent grant