CN114942767A - JSON file parsing method and device - Google Patents

JSON file parsing method and device Download PDF

Info

Publication number
CN114942767A
CN114942767A CN202210538338.7A CN202210538338A CN114942767A CN 114942767 A CN114942767 A CN 114942767A CN 202210538338 A CN202210538338 A CN 202210538338A CN 114942767 A CN114942767 A CN 114942767A
Authority
CN
China
Prior art keywords
file
target
map
json
analysis
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
CN202210538338.7A
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.)
Bank of China Financial Technology Co Ltd
Original Assignee
Bank of China Financial Technology 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 Bank of China Financial Technology Co Ltd filed Critical Bank of China Financial Technology Co Ltd
Priority to CN202210538338.7A priority Critical patent/CN114942767A/en
Publication of CN114942767A publication Critical patent/CN114942767A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • G06F8/436Semantic checking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files
    • G06F9/4451User profiles; Roaming

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a JSON file analyzing method and device, and the method comprises the following steps: determining a target lightweight data exchange format JSON file by adopting a polling mode based on the configuration file; generating a first Map and a second Map based on the configuration file, wherein keys of the first Map correspond to keys of the second Map one by one, a value of the first Map is used for storing an analysis result of the target JSON, and a value of the second Map is used for storing an analysis file name; based on the configuration file, utilizing a Java reflection mechanism to analyze the target JSON file one by one, and storing an analysis result into the value of the first Map according to a key corresponding to each piece of data; and when the analysis is completed, generating an analysis file based on the analysis file names in the first Map and the second Map, so that the analysis efficiency of the JSON file is improved.

Description

JSON file parsing method and device
Technical Field
The application relates to the technical field of computers, in particular to a JSON file parsing method and device.
Background
In the prior art, a process of parsing a lightweight data exchange format (JSON) file can only be developed according to a single JSON, which is large in workload and prone to errors.
Disclosure of Invention
The application provides a JSON file parsing method and device, which are used for overcoming the defect that the efficiency of parsing a JSON file in the prior art is low, and improving the efficiency of parsing the JSON file.
The application provides a JSON file parsing method, which comprises the following steps:
determining a target lightweight data exchange format JSON file by adopting a polling mode based on the configuration file;
generating a first Map and a second Map based on the configuration file, wherein keys of the first Map correspond to keys of the second Map one by one, values of the first Map are used for storing analysis results of the target JSON, and values of the second Map are used for storing analysis file names;
based on the configuration file, utilizing a Java reflection mechanism to analyze the target JSON file one by one, and storing an analysis result into the value of the first Map according to a key corresponding to each piece of data;
and generating an analysis file based on the analysis file name in the first Map and the second Map when the analysis is completed.
According to the JSON file analysis method provided by the application, the method for determining the target lightweight class data exchange format JSON file by adopting a polling mode based on the configuration file comprises the following steps:
determining a target regular expression from a plurality of regular expressions in the configuration file, and determining a file name corresponding to the regular expression;
determining whether a file corresponding to the file name exists in a target directory at intervals of target time in a polling mode;
and when the target directory has a file corresponding to the file name, determining the target JSON file as the file corresponding to the file name.
According to the JSON file parsing method provided by the application, the determining a target regular expression from a plurality of regular expressions in the configuration file includes:
determining a regular expression to be selected from a plurality of regular expressions in the configuration file by traversing the configuration file;
determining whether the file corresponding to the regular expression to be selected is analyzed or not by determining whether the identification file corresponding to the regular expression to be selected exists or not;
under the condition that the file corresponding to the regular expression to be selected is not analyzed, determining the target regular expression as the regular expression to be selected, and creating an identification file corresponding to the regular expression to be selected; alternatively, the first and second electrodes may be,
and under the condition that the file corresponding to the regular expression to be selected is analyzed, continuously traversing the configuration file, and updating the regular expression to be selected until the file corresponding to the regular expression to be selected is determined not to be analyzed.
According to the JSON file parsing method provided by the application, the first Map comprises a plurality of keys and a value corresponding to each key;
the analyzing the target JSON file one by using a Java reflection mechanism based on the configuration file, and storing an analysis result into the value of the first Map according to a key corresponding to each piece of data, including:
and for the ith data in the target JSON file, determining a target key corresponding to the ith data from the plurality of keys, wherein i is a positive integer, and the initial value of i is 1.
Analyzing the ith data by using a Java reflection mechanism based on the configuration file to obtain an analysis result, and updating the value corresponding to the target key according to the analysis result;
and executing an adding operation on the i to continuously analyze the next piece of data in the target JSON file until the analysis result of all the data in the target JSON file is stored in the value of the first Map.
According to the JSON file parsing method provided by the application, parsing the ith piece of data by using a Java reflection mechanism based on the configuration file includes:
determining a target analysis method for analyzing the ith data based on the configuration file;
and calling the target analysis method to analyze the ith piece of data by using a reflection mechanism of Java, wherein the target analysis method is used for determining the field sequence and the separators in the generated file.
The application provides a JSON file parsing device, which comprises:
the polling module is used for determining a target lightweight data exchange format JSON file by adopting a polling mode based on the configuration file;
the reading module is used for generating a first Map and a second Map based on the configuration file, keys of the first Map and keys of the second Map are in one-to-one correspondence, a value of the first Map is used for storing an analysis result of the target JSON, and a value of the second Map is used for storing an analysis file name;
the analysis module is used for analyzing the target JSON file one by utilizing a Java reflection mechanism based on the configuration file and storing an analysis result into the value of the first Map according to the key corresponding to each piece of data;
and the generating module is used for generating an analysis file based on the analysis file name in the first Map and the second Map under the condition of analysis completion.
According to the JSON file parsing apparatus provided in the present application, the polling module is further configured to:
determining a target regular expression from a plurality of regular expressions in the configuration file, and determining a file name corresponding to the regular expression;
determining whether a file corresponding to the file name exists in a target directory at intervals of target time in a polling mode;
and when the target directory has a file corresponding to the file name, determining the target JSON file as the file corresponding to the file name.
The application also provides an electronic device, which comprises a memory, a processor and a computer program which is stored on the memory and can run on the processor, wherein when the processor executes the program, the JSON file parsing method is realized.
The present application also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a JSON file parsing method as described in any of the above.
The application also provides a computer program product, which comprises a computer program, and when the computer program is executed by a processor, the computer program realizes the JSON file parsing method.
According to the JSON file parsing method and device, the target JSON file is determined in a polling mode based on the configuration file, the target JSON file is parsed by using a Java reflection mechanism based on the configuration file, a parsing result is stored in the first MAP, after parsing is completed, a parsing file is generated based on the first MAP, a plurality of JSON files are parsed through configuration and entity writing, the parsing process of each JSON file does not need to be developed, and therefore a simple method is provided for the parsing process of the complex JSON files, and the parsing efficiency of the JSON files is improved.
Drawings
In order to more clearly illustrate the technical solutions in the present application or the prior art, the drawings needed for the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic flow diagram of a JSON file parsing method provided in the present application;
fig. 2 is a schematic flowchart of determining a target JSON file in a polling manner based on a configuration file according to the present application;
fig. 3 is a schematic flow diagram that content in a target JSON file is analyzed item by item and an analysis result is stored in the value of the first Map according to a key corresponding to each piece of data, according to the present application;
fig. 4 is a schematic structural diagram of a JSON file parsing apparatus provided in the present application;
fig. 5 is a schematic structural diagram of an electronic device provided in the present application.
Detailed Description
To make the purpose, technical solutions and advantages of the present application clearer, the technical solutions in the present application will be clearly and completely described below with reference to the drawings in the present application, and it is obvious that the described embodiments are some, but not all embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Fig. 1 is a schematic flow diagram of a JSON file parsing method provided in an embodiment of the present application, and as shown in fig. 1, the JSON file parsing method includes: step 100, step 101, step 102 and step 103.
Step 100, determining a target lightweight data exchange format JSON file in a polling mode based on the configuration file.
Optionally, the target JSON file is a JSON to be parsed that is issued by the upstream system to the specified directory.
The configuration file comprises basic information of a plurality of JSON files, wherein the basic information of the target JSON file is included.
The configuration file is configured for each JSON file needing to be analyzed, and comprises a JSON file compression name, a decompressed file, a JSON file format, a file format to be generated and the like. The compressed name of the JSON file can be uniquely matched through a regular expression.
When a downstream system receives a new JSON file, the basic information of the JSON file is configured into a configuration file, and the configuration file may be configured manually or in other manners.
Optionally, since the arrival time of the target JSON file is uncertain, polling may be performed by configuring schedule, and the target JSON file may be parsed after being scanned in the round robin process.
Fig. 2 is a schematic flowchart of determining a target JSON file in a polling manner based on a configuration file according to an embodiment of the present application, and in some embodiments, as shown in fig. 2, step 100 includes: step 200, step 201 and step 202.
Step 200, determining a target regular expression from a plurality of regular expressions in the configuration file, and determining a file name corresponding to the regular expression.
It should be noted that basic information of multiple JSON files is configured in a configuration file, that is, multiple JSON files with parsing exist, that is, multiple regular expressions are included. Therefore, a target regular expression, that is, a regular expression corresponding to a file that needs to be analyzed currently, needs to be determined from a plurality of regular expressions.
In some embodiments, step 200 comprises:
determining a regular expression to be selected from a plurality of regular expressions in the configuration file by traversing the configuration file;
determining whether the file corresponding to the regular expression to be selected is analyzed or not by determining whether the identification file corresponding to the regular expression to be selected exists or not;
under the condition that the file corresponding to the regular expression to be selected is not analyzed, determining the target regular expression as the regular expression to be selected, and creating an identification file corresponding to the regular expression to be selected; alternatively, the first and second electrodes may be,
and under the condition that the file corresponding to the regular expression to be selected is analyzed, continuously traversing the configuration file, and updating the regular expression to be selected until the file corresponding to the regular expression to be selected is determined not to be analyzed.
Optionally, a regular expression to be selected may be determined from the plurality of regular expressions by traversing the configuration file, and the regular expression to be selected may be a next regular expression of the regular expression currently being parsed.
It should be noted that parsing the JSON file may be executed concurrently, that is, there may be multiple threads parsing the JSON file in the configuration file at the same time, and therefore, before parsing the JSON file, one thread needs to determine whether the JSON file is being parsed by another thread.
In the process of resolving JSON, an identification file corresponding to the JSON, for example, a file with ok as a suffix name, is generated, so that concurrence control can be performed through the identification file.
For example, whether a file with ok as a suffix name and a file name corresponding to the regular expression to be selected exists is determined. If so, proving that the file corresponding to the regular expression to be selected is being analyzed; if the configuration file does not exist, the file corresponding to the regular expression to be selected is proved not to be analyzed, at the moment, the configuration file corresponding to the regular expression to be selected is generated, other processes can detect the configuration file, and the JSON file corresponding to the regular expression to be selected cannot be analyzed by other processes.
According to the JSON file analyzing method provided by the embodiment of the application, whether the file corresponding to the regular expression to be selected is analyzed or not is determined by determining whether the identification file corresponding to the regular expression to be selected exists or not, the condition that the file is analyzed by other processes in the concurrent process is eliminated, the concurrent control can be performed, the JSON file is ensured not to be repeatedly analyzed, and the file analyzing efficiency is improved.
Step 201, determining whether a file corresponding to the file name exists in the target directory every target time by adopting a polling mode.
The target directory may be a directory stored in the JSON file after the JSON file is issued by the upstream system.
Optionally, since the specific arrival time of the file is not known, it may be determined whether the file corresponding to the file name exists in the target directory every target time in a polling manner.
The target time may be set as desired, for example, by cycling through the parsing process every 5 minutes.
Step 202, when a file corresponding to the file name exists in the target directory, determining that the target JSON file is the file corresponding to the file name.
It can be understood that, in the case that a file corresponding to the file name exists in the target directory, the certification file has been issued to the target directory, and the file corresponding to the file name is the target JSON file.
The JSON file analyzing method provided by the embodiment of the application determines the target regular expression from the regular expressions in the configuration file, determines whether the target directory has the file corresponding to the target regular expression or not in a polling mode, thereby determining the target JSON file, and realizes that the target JSON file is determined from the directory through the configuration file, namely the JSON file is determined one by one after being issued through configuration, and then the subsequent analysis is carried out.
Step 101, generating a first Map and a second Map based on the configuration file, wherein keys of the first Map correspond to keys of the second Map one by one, values of the first Map are used for storing analysis results of the target JSON, and values of the second Map are used for storing analysis file names.
The configuration file includes the object configuration information of the target JSON file, that is, the parse configuration part.
Optionally, a first Map storing the parsing result and a second Map of the file name after the file is compressed are generated according to the parse configuration part.
Map is an object for mapping keys to values, and the key of the first Map is the fileName of each object of the target JSON file in the parse configuration; the value is data that is parsed out and appended line by line.
For example, the target JSON file has a total of six objects, that is, can be parsed into six subfiles. The filenames of the six objects are respectively: GS00006D.CH1, GS00006D.CH2, GS00006D.CH3, GS00006D.CH4, GS00006D.CH5 and GS00006D.CH6. Each object corresponds to a value, and each value initial value may be null, and is used to store the result after each object is analyzed.
The key of the second Map may be the same as the key of the first Map, the value of the second Map being: GS00006D.CH1.gz.202201240, GS00006D.CH2.gz.202201240, GS00006D.CH3.gz.202201240, GS00006D.CH4.gz.202201240, GS00006D.CH5.gz.202201240 and GS00006D.CH6.gz.202201240.
And 102, analyzing the target JSON file one by using a Java reflection mechanism based on the configuration file, and storing an analysis result into the value of the first Map according to a key corresponding to each piece of data.
It should be noted that, in the development process, the corresponding JSON file may be configured according to the configuration rules and requirements, a simple entity file is written, the tosting method or other defined methods are rewritten or reconstructed in the entity, and the configuration and the entity are associated by using the Java reflection mechanism, so as to obtain the desired string format according to the tosting method of the entity. According to the method, the analysis process is independent, the analysis method is called through schedule round robin, the configuration information is read in the analysis method, and the JSON file is analyzed after being scanned in the round robin process after arriving.
It should be noted that, each is also referred to as a line by line, that is, one line is a complete JSONObject, and the complexity of each JSONObject object may be different, because the JSONObject is a complete piece of data, the whole file does not need to be read into the memory for conversion, thereby saving the memory resource.
Optionally, the target JSON file is opened and read item by item.
It should be noted that, for JSON files stored in rows, reading can be directly performed one by one; for the files which are not read according to the row, the files need to be read into a target JSON file in a memory, and then the analysis process is carried out.
In some embodiments, the first Map includes a plurality of keys, and a value corresponding to each key. Fig. 3 is a schematic flowchart of a process of parsing contents in a target JSON file item by item and storing a parsing result in a first Map according to an embodiment of the present application, and as shown in fig. 3, step 102 includes step 300, step 301, and step 302.
Step 300, for the ith data in the target JSON file, determining a target key corresponding to the ith data from the plurality of keys, wherein i is a positive integer, and the initial value of i is 1.
Optionally, the target JSON file includes multiple pieces of data, and information of each piece of data may be stored in different subfiles after parsing.
For example, the target JSON file is a beneficial owner change information file issued by an upstream system, and the file includes 6 pieces of information, such as a main enterprise basic information change, a direct or indirect stock beneficial owner change, a personnel financial controller change, a high-level manager change, a legal representative/responsible/executive business partner change, and a beneficial owner change, so that the file needs to be parsed into 6 files to a designated directory.
Optionally, the target JSON file needs to be parsed into how many sub-files, and thus how many keys exist in the first Map, and the parsed content of each sub-file is stored into the value corresponding to each key.
Step 301, analyzing the ith data by using a reflection mechanism of Java based on the configuration file to obtain an analysis result, and updating the value corresponding to the target key according to the analysis result.
The Java reflection mechanism refers to that in the running state of a program, an object of any class can be constructed, the class to which any object belongs can be known, member variables and methods of any class can be known, and the attribute and method of any object can be called. This function of dynamically acquiring program information and dynamically calling objects is called a reflection mechanism of the Java language.
By using a Java reflection mechanism, a toString method of an entity can be called to analyze data.
And continuously splicing the analysis results according to the sequence to update the value corresponding to the target key.
In some embodiments, parsing the ith piece of data using a reflection mechanism of Java based on the configuration file includes:
determining a target analysis method for analyzing the ith data based on the configuration file;
and calling the target analysis method to analyze the ith piece of data by using a reflection mechanism of Java, wherein the target analysis method is used for determining the field sequence and the separators in the generated file.
Alternatively, the target parsing method may be determined according to a method parameter in the configuration file, and when the value of the type parameter is child, the toString method is called as long as the method parameter is not null.
And (3) utilizing a reflection mechanism of Java to call a toString method to analyze the data, determining a field sequence and a separator in an analysis result, and adding the analysis result to a value corresponding to the target key.
And step 302, executing an adding operation on the i to continuously analyze the next piece of data in the target JSON file until the analysis results of all data in the target JSON file are stored in the value of the first Map.
It can be understood that the adding one operation is performed on i, so that the next piece of data in the target JSON file can be continuously parsed, that is, after the adding one operation is performed on i, step 301 is returned to, the next piece of data in the target JSON file is continuously parsed until all data in the target JSON file is completely parsed, and the parsing result is stored in the first Map.
According to the JSON file analysis method provided by the embodiment of the application, for each piece of data in the target JSON file, the target key corresponding to the data is determined from a plurality of keys of the first Map, the target analysis method for analyzing the data is determined based on the configuration file, the target analysis method is called by using a Java reflection mechanism to analyze the data, the analysis result is stored into the value corresponding to the target key, the next piece of data in the target JSON file is continuously analyzed after the storage is completed until the analysis results of all the data in the target JSON file are stored into the first Map, the plurality of JSON files are analyzed through configuration and entity writing, the analysis process of each JSON file is not required to be developed, and therefore a simple method is provided for the analysis process of the complex JSON file, and the analysis efficiency of the JSON file is improved.
And 103, generating an analysis file based on the analysis file names in the first Map and the second Map under the condition of completing analysis.
And generating an analysis file after the analysis is finished, wherein the process comprises file generation, compression and renaming.
Generating a file based on the key-value pairs in the first Map, taking the parsing file gs00006d.syr.gz.202201241 as an example, six key-value pairs in the parsed first Map, that is, six files need to be parsed: gs00006d.ch1.gz.2022012400, gs00006d.ch2.gz.2022012400, gs00006d.ch3.gz.2022012400, gs00006d.ch4.gz.2022012400, gs00006d.ch5.gz.2022012400 and gs00006d.ch6.gz.2022012400.
In addition, a source file needs to be backed up, namely a target JSON file is backed up, then the target JSON file is deleted in the target directory, a process file generated in the parsing process is deleted, and an identification file is deleted.
According to the JSON file parsing method provided by the embodiment of the application, the target JSON file is determined based on the configuration file in a polling mode, the target JSON file is parsed based on the configuration file by using a Java reflection mechanism, a parsing result is stored in the first MAP, after parsing is completed, a parsing file is generated based on the first MAP, a plurality of JSON files are parsed by configuration and entity writing, the parsing process of each JSON file does not need to be developed, and therefore a simple method is provided for the parsing process of the complex JSON files, and the parsing efficiency of the JSON files is improved.
The JSON file parsing apparatus provided in the present application is described below, and the JSON file parsing apparatus described below and the JSON file parsing method described above may be referred to correspondingly.
As shown in fig. 4, the JSON file parsing apparatus 400 includes: a polling module 410, a reading module 420, a parsing module 430, and a generating module 440.
The polling module 410 is configured to determine a target lightweight data exchange format JSON file in a polling manner based on the configuration file;
a reading module 420, configured to generate a first Map and a second Map based on the configuration file, where a key of the first Map corresponds to a key of the second Map one to one, a value of the first Map is used to store an analysis result of the target JSON, and a value of the second Map is used to store an analysis file name;
the parsing module 430 is configured to parse the target JSON file item by utilizing a reflection mechanism of Java based on the configuration file, and store a parsing result in the value of the first Map according to a key corresponding to each piece of data;
a generating module 440, configured to generate an analysis file based on the analysis file names in the first Map and the second Map when analysis is completed.
Optionally, the polling module 410 is further configured to:
determining a target regular expression from a plurality of regular expressions in the configuration file, and determining a file name corresponding to the regular expression;
determining whether a file corresponding to the file name exists in a target directory at intervals of target time in a polling mode;
and when the target directory has a file corresponding to the file name, determining the target JSON file as the file corresponding to the file name.
Optionally, the determining a target regular expression from a plurality of regular expressions in the configuration file includes:
determining a regular expression to be selected from a plurality of regular expressions in the configuration file by traversing the configuration file;
determining whether the file corresponding to the regular expression to be selected is analyzed or not by determining whether the identification file corresponding to the regular expression to be selected exists or not;
under the condition that the file corresponding to the regular expression to be selected is not analyzed, determining the target regular expression as the regular expression to be selected, and creating an identification file corresponding to the regular expression to be selected; alternatively, the first and second electrodes may be,
and under the condition that the file corresponding to the regular expression to be selected is analyzed, continuously traversing the configuration file, and updating the regular expression to be selected until the file corresponding to the regular expression to be selected is determined not to be analyzed.
Optionally, the first Map includes a plurality of keys, and a value corresponding to each key;
the analyzing the target JSON file one by using a reflection mechanism of Java based on the configuration file, and storing an analysis result into the value of the first Map according to a key corresponding to each piece of data, including:
and for the ith data in the target JSON file, determining a target key corresponding to the ith data from the plurality of keys, wherein i is a positive integer, and the initial value of i is 1.
Analyzing the ith data by using a Java reflection mechanism based on the configuration file to obtain an analysis result, and updating the value corresponding to the target key according to the analysis result;
and executing an adding operation on the i to continuously analyze the next piece of data in the target JSON file until the analysis result of all the data in the target JSON file is stored in the value of the first Map.
Optionally, the parsing the ith piece of data by using a reflection mechanism of Java based on the configuration file includes:
determining a target analysis method for analyzing the ith data based on the configuration file;
and calling the target analysis method to analyze the ith piece of data by using a reflection mechanism of Java, wherein the target analysis method is used for determining the field sequence and the separators in the generated file.
It should be noted that the apparatus provided in the embodiment of the present application can implement all the method steps implemented by the method embodiment and achieve the same technical effect, and detailed descriptions of the same parts and beneficial effects as the method embodiment in this embodiment are omitted here.
Fig. 5 illustrates a physical structure diagram of an electronic device, which may include, as shown in fig. 5: a processor (processor)510, a communication Interface (Communications Interface)520, a memory (memory)530 and a communication bus 540, wherein the processor 510, the communication Interface 520 and the memory 530 communicate with each other via the communication bus 540. Processor 510 may call logic instructions in memory 530 to perform a JSON file parsing method comprising: determining a target lightweight data exchange format JSON file by adopting a polling mode based on the configuration file;
generating a first Map and a second Map based on the configuration file, wherein keys of the first Map correspond to keys of the second Map one by one, values of the first Map are used for storing analysis results of the target JSON, and values of the second Map are used for storing analysis file names;
based on the configuration file, utilizing a Java reflection mechanism to analyze the target JSON file one by one, and storing an analysis result into the value of the first Map according to a key corresponding to each piece of data;
and under the condition that the analysis is completed, generating an analysis file based on the analysis file name in the first Map and the second Map.
Furthermore, the logic instructions in the memory 530 may be implemented in the form of software functional units and stored in a computer readable storage medium when the software functional units are sold or used as independent products. Based on such understanding, the technical solution of the present application or portions thereof that substantially contribute to the prior art may be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In another aspect, the present application further provides a computer program product, where the computer program product includes a computer program, the computer program can be stored on a non-transitory computer readable storage medium, and when the computer program is executed by a processor, a computer can execute the JSON file parsing method provided by the above methods, and the method includes:
determining a target lightweight data exchange format JSON file by adopting a polling mode based on the configuration file;
generating a first Map and a second Map based on the configuration file, wherein keys of the first Map correspond to keys of the second Map one to one, a value of the first Map is used for storing an analysis result of the target JSON, and a value of the second Map is used for storing an analysis file name;
based on the configuration file, utilizing a Java reflection mechanism to analyze the target JSON file one by one, and storing an analysis result into the value of the first Map according to a key corresponding to each piece of data;
and under the condition that the analysis is completed, generating an analysis file based on the analysis file name in the first Map and the second Map.
In yet another aspect, the present application further provides a non-transitory computer readable storage medium, on which a computer program is stored, the computer program being implemented by a processor to execute the JSON file parsing method provided by the above methods, the method including:
determining a target lightweight data exchange format JSON file by adopting a polling mode based on the configuration file;
generating a first Map and a second Map based on the configuration file, wherein keys of the first Map correspond to keys of the second Map one by one, values of the first Map are used for storing analysis results of the target JSON, and values of the second Map are used for storing analysis file names;
based on the configuration file, utilizing a Java reflection mechanism to analyze the target JSON file one by one, and storing an analysis result into the value of the first Map according to a key corresponding to each piece of data;
and under the condition that the analysis is completed, generating an analysis file based on the analysis file name in the first Map and the second Map.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one position, or may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.

Claims (10)

1. A JSON file parsing method is characterized by comprising the following steps:
determining a target lightweight data exchange format JSON file by adopting a polling mode based on the configuration file;
generating a first Map and a second Map based on the configuration file, wherein keys of the first Map correspond to keys of the second Map one by one, values of the first Map are used for storing analysis results of the target JSON, and values of the second Map are used for storing analysis file names;
based on the configuration file, utilizing a Java reflection mechanism to analyze the target JSON file one by one, and storing an analysis result into the value of the first Map according to a key corresponding to each piece of data;
and under the condition that the analysis is completed, generating an analysis file based on the analysis file name in the first Map and the second Map.
2. The method for parsing the JSON file according to claim 1, wherein the determining the target lightweight JSON file in the data exchange format in a polling manner based on the configuration file comprises:
determining a target regular expression from a plurality of regular expressions in the configuration file, and determining a file name corresponding to the regular expression;
determining whether a file corresponding to the file name exists in a target directory at intervals of target time in a polling mode;
and when the target directory has a file corresponding to the file name, determining the target JSON file as the file corresponding to the file name.
3. The method for parsing a JSON file according to claim 2, wherein the determining a target regular expression from a plurality of regular expressions in the configuration file includes:
determining a regular expression to be selected from a plurality of regular expressions in the configuration file by traversing the configuration file;
determining whether the file corresponding to the regular expression to be selected is analyzed or not by determining whether the identification file corresponding to the regular expression to be selected exists or not;
under the condition that the file corresponding to the regular expression to be selected is not analyzed, determining the target regular expression as the regular expression to be selected, and creating an identification file corresponding to the regular expression to be selected; alternatively, the first and second electrodes may be,
and under the condition that the file corresponding to the regular expression to be selected is analyzed, continuously traversing the configuration file, and updating the regular expression to be selected until the file corresponding to the regular expression to be selected is determined not to be analyzed.
4. The JSON file parsing method according to claim 1, wherein the first Map includes a plurality of keys, and a value corresponding to each key;
the analyzing the target JSON file one by using a reflection mechanism of Java based on the configuration file, and storing an analysis result into the value of the first Map according to a key corresponding to each piece of data, including:
and for the ith data in the target JSON file, determining a target key corresponding to the ith data from the multiple keys, wherein i is a positive integer, and the initial value of i is 1.
Analyzing the ith data by using a Java reflection mechanism based on the configuration file to obtain an analysis result, and updating the value corresponding to the target key according to the analysis result;
and executing an adding operation on the i to continuously analyze the next piece of data in the target JSON file until the analysis result of all the data in the target JSON file is stored in the value of the first Map.
5. The method for parsing the JSON file according to claim 4, wherein parsing the ith piece of data by using a reflection mechanism of Java based on the configuration file includes:
determining a target analysis method for analyzing the ith data based on the configuration file;
and calling the target analysis method to analyze the ith piece of data by using a reflection mechanism of Java, wherein the target analysis method is used for determining the field sequence and the separators in the generated file.
6. A JSON file parsing device is characterized by comprising:
the polling module is used for determining a target lightweight data exchange format JSON file in a polling mode based on the configuration file;
the reading module is used for generating a first Map and a second Map based on the configuration file, keys of the first Map and keys of the second Map are in one-to-one correspondence, a value of the first Map is used for storing an analysis result of the target JSON, and a value of the second Map is used for storing an analysis file name;
the analysis module is used for analyzing the target JSON file one by utilizing a Java reflection mechanism based on the configuration file and storing an analysis result into the value of the first Map according to the key corresponding to each piece of data;
and the generating module is used for generating an analysis file based on the analysis file name in the first Map and the second Map under the condition of analysis completion.
7. The JSON file parsing device of claim 6, wherein the polling module is further configured to:
determining a target regular expression from a plurality of regular expressions in the configuration file, and determining a file name corresponding to the regular expression;
determining whether a file corresponding to the file name exists in a target directory at intervals of target time in a polling mode;
and when the target directory has a file corresponding to the file name, determining the target JSON file as the file corresponding to the file name.
8. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the JSON file parsing method according to any one of claims 1 to 5 when executing the program.
9. A non-transitory computer readable storage medium having stored thereon a computer program, wherein the computer program when executed by a processor implements the JSON file parsing method according to any one of claims 1 to 5.
10. A computer program product comprising a computer program, wherein the computer program, when executed by a processor, implements the JSON file parsing method of any one of claims 1 to 5.
CN202210538338.7A 2022-05-17 2022-05-17 JSON file parsing method and device Pending CN114942767A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210538338.7A CN114942767A (en) 2022-05-17 2022-05-17 JSON file parsing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210538338.7A CN114942767A (en) 2022-05-17 2022-05-17 JSON file parsing method and device

Publications (1)

Publication Number Publication Date
CN114942767A true CN114942767A (en) 2022-08-26

Family

ID=82906356

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210538338.7A Pending CN114942767A (en) 2022-05-17 2022-05-17 JSON file parsing method and device

Country Status (1)

Country Link
CN (1) CN114942767A (en)

Similar Documents

Publication Publication Date Title
CN107370786B (en) General information management system based on micro-service architecture
US10915544B2 (en) Transforming and loading data utilizing in-memory processing
US20210342313A1 (en) Autobuild log anomaly detection methods and systems
Bischl et al. BatchJobs and BatchExperiments: Abstraction mechanisms for using R in batch environments
US20140075242A1 (en) Testing rest api applications
US10162735B2 (en) Distributed system test automation framework
US8832125B2 (en) Extensible event-driven log analysis framework
CN108280023B (en) Task execution method and device and server
US20130262461A1 (en) Method and System for Centralized Issue Tracking
CN112380180A (en) Data synchronization processing method, device, equipment and storage medium
US11971882B2 (en) System and method for batch and real-time feature computation
US8775392B1 (en) Revision control and configuration management
CN112835924A (en) Real-time computing task processing method, device, equipment and storage medium
JP2018060570A (en) Reference data segmentation from single to multiple tables
CN111737140A (en) Interface automation test method, device, equipment and computer readable storage medium
US20140157227A1 (en) Method and system for preserving restful web service structure in a client consuming the restful web service
CN113641739B (en) Spark-based intelligent data conversion method
CN112559525B (en) Data checking system, method, device and server
US20210124752A1 (en) System for Data Collection, Aggregation, Storage, Verification and Analytics with User Interface
CN115994085A (en) Code coverage rate test processing method, device, equipment and storage medium
CN116303494A (en) System and method for carrying out consistency analysis on massive multi-source heterogeneous data of certificate core transaction system based on distributed database
CN114942767A (en) JSON file parsing method and device
US11392486B1 (en) Multi-role, multi-user, multi-technology, configuration-driven requirements, coverage and testing automation
KR20200103133A (en) Method and apparatus for performing extract-transfrom-load procedures in a hadoop-based big data processing system
Settle et al. aMatReader: Importing adjacency matrices via Cytoscape Automation

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