CN112836475A - Method for converting mixed JSON and XML data into two-dimensional array - Google Patents

Method for converting mixed JSON and XML data into two-dimensional array Download PDF

Info

Publication number
CN112836475A
CN112836475A CN202110238573.8A CN202110238573A CN112836475A CN 112836475 A CN112836475 A CN 112836475A CN 202110238573 A CN202110238573 A CN 202110238573A CN 112836475 A CN112836475 A CN 112836475A
Authority
CN
China
Prior art keywords
character string
java
json
xml
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110238573.8A
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.)
Liaoning Zhenxing Bank Co ltd
Original Assignee
Liaoning Zhenxing Bank 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 Liaoning Zhenxing Bank Co ltd filed Critical Liaoning Zhenxing Bank Co ltd
Publication of CN112836475A publication Critical patent/CN112836475A/en
Pending legal-status Critical Current

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/151Transformation
    • G06F40/154Tree transformation for tree-structured or markup documents, e.g. XSLT, XSL-FO or stylesheets

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Document Processing Apparatus (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method for converting mixed JSON and XML data into a two-dimensional array, which relates to the technical field of computer data and comprises the following steps: judging whether the character string ends with the start of the { "and the end of the" } ", and trying to resolve the character string into an object by using a java JSON resolving tool, wherein the object is a JSON object if the character string can be resolved. According to the method for converting the mixed JSON and XML data into the two-dimensional array, the data needing to be converted is processed through the program flow formed by the method, the method can support the analysis of the mixed data, the mixed use of a plurality of flows and various tools is avoided, the data analysis and processing flows are simplified, the extraction and analysis of the data are accelerated, and the problem that the data processing inconvenience is caused to users due to the fact that most of the tools cannot analyze the complex data with JSON and XML and cannot conveniently convert the needed data into the general two-dimensional array is solved.

Description

Method for converting mixed JSON and XML data into two-dimensional array
Technical Field
The invention relates to the technical field of computer data, in particular to a method for converting mixed JSON and XML data into a two-dimensional array.
Background
XML, the abbreviation of EXtensible Markup Language, XML, is a Markup Language similar to HTML, in which XML is used to describe data, Markup that is used to describe XML, is not predefined in XML, you must define their own Markup XML using Document Type Definitions (DTD) or Schema (Schema) to describe data, XML, which is a self-describing Language used to store data, using DTD or Schema, is not a substitute for HTML, XML and HTML are two different purpose languages, HTML is related to display information, XML is related to description information, "XML" is a Language for data exchange over the network, has a format similar to the "HTML" Language used to describe Web pages, JSON is a text format for structured data serialization derived from object real words of Javascript, which is defined in the third edition of the ecr Language standard, and can describe four simple types (JSON strings, numbers, cloth values and null) and two structured types (objects and arrays), string (string) is a sequence of zero or more Unicode characters, object (object) is a set of unordered zero or more name/value (name/value) pairs, where name is a string type, value can be a string, number, bolt, null, object, or array type, array (array) is an ordered sequence of zero or more values, the terms "object" and "array" are from the JavaScript specification, JSON is designed with the goal of making it small, lightweight, textual, and a subset of JavaScript and is a subset of JavaScript and because the data that mixes JSON and XML is parsed into two-dimensional arrays and JSON and XML belong to a common message format, based on the different technology stacks and tools used, it has more parsing tools and parsing methods, respectively, and parsing XML or data, but the tools or methods that parse XML and XML cross-kernel data once are less and can handle most of XML data alone or just a single tool, the mixed processing cannot be carried out, and meanwhile, most tools cannot be used universally for analyzing complex XML and JSON, so most of the tools cannot analyze complex data with JSON and XML at the same time, and further cannot conveniently convert required data into a universal two-dimensional array by users, so that the data processing of the users is inconvenient, and therefore, a method for converting mixed JSON and XML data into a two-dimensional array is provided to solve the problem.
Disclosure of Invention
Technical problem to be solved
Aiming at the defects of the prior art, the invention provides a method for converting mixed JSON and XML data into a two-dimensional array, and solves the problem that most of the existing tools cannot analyze complex data simultaneously existing in JSON and XML, so that users cannot conveniently convert required data into a universal two-dimensional array, and accordingly data processing of the users is inconvenient.
(II) technical scheme
In order to achieve the above purposes, the technical scheme adopted by the invention is as follows: a method for converting mixed JSON and XML data into a two-dimensional array comprises the following steps:
and S1, judging whether the character string ends with the ' { ' beginning and ' } ', attempting to analyze the character string into an object by using a java JSON analysis tool, if the character string can be analyzed, determining the JSON object, if the character string ends with the ' [ ' beginning and ' ] ', attempting to analyze the character string into an array by using the java JSON analysis tool, if the character string can be analyzed, determining the JSON array, if the character string ends with the ' < ' beginning and ' >, attempting to analyze the character string into the object by using a java xml tool, if the character string ends with the ' < ' beginning and the ' >, determining the character string into an xml message, and if the character string ends with the ' >, converting the character string.
And S2, using java json to analyze the message and converting the message into a java map or java list object.
And S3, traversing the java map or java list object and executing the step S1.
And S4, converting the message into a java Element object by using java xml to analyze the message.
And S5, traversing the attributes and the contents of the java elements and executing the step S1.
S6, the result is stored in the result stack in the form of character string.
Use of a method for converting mixed JSON and XML data into a two-dimensional array, comprising the steps of:
firstly, placing a data packet character string which needs to be analyzed into a universal two-dimensional array for processing into the method, then, carrying out the first step of the method, namely judging whether the character string is judged at the beginning of { "and at the end of" } ", attempting to analyze the character string into an object by using a java JSON analysis tool, if the character string can be analyzed, determining a JSON object, if the character string is judged at the end of" [ "and at the end of" ] ", attempting to analyze the character string into an array by using a java JSON analysis tool, if the character string can be analyzed, determining the JSON array, if the character string can be analyzed, attempting to analyze the character string into the object by using a java xml tool, if the analysis is successful, determining the character string into an xml message, otherwise, carrying out the second step, namely converting the character string into a java map or a java list object by using the java JSON the second step, then carrying out the first step after traversing the java map or java list object, then executing the fourth step of using java xml to analyze the message, converting the message into a java Element object, then executing the fifth step of traversing the attribute and the content of the java Element, finally executing the first step and executing the last step of storing the conversion result into a result stack in a character string mode to finish the conversion work
(III) advantageous effects
The invention has the beneficial effects that:
according to the method for converting the mixed JSON and XML data into the two-dimensional array, the data needing to be converted is processed through the program flow formed by the method, the method can support the analysis of the mixed data, the mixed data is prevented from being used by a plurality of flows and various tools in a mixed mode, then the function of analyzing the mixed data of the XML and the JSON in one step is achieved, the data analyzing and processing flows are simplified, the extraction and analysis of the data are accelerated, and the problem that the data processing inconvenience is caused by the fact that most of the existing tools cannot analyze the complex data with the JSON and the XML and cannot conveniently convert the needed data into the universal two-dimensional array by users is solved.
Drawings
FIG. 1 is a schematic diagram of a hybrid XML and JSON data parsing flow structure of the present invention;
fig. 2 is a schematic diagram of a data analysis process according to the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
As shown in fig. 1-2, the present invention provides a technical solution: a method for converting mixed JSON and XML data into a two-dimensional array comprises the following steps:
and S1, judging whether the character string ends with the ' { ' beginning and ' } ', attempting to analyze the character string into an object by using a java JSON analysis tool, if the character string can be analyzed, determining the JSON object, if the character string ends with the ' [ ' beginning and ' ] ', attempting to analyze the character string into an array by using the java JSON analysis tool, if the character string can be analyzed, determining the JSON array, if the character string ends with the ' < ' beginning and ' >, attempting to analyze the character string into the object by using a java xml tool, if the character string ends with the ' < ' beginning and the ' >, determining the character string into an xml message, and if the character string ends with the ' >, converting the character string.
And S2, using java json to analyze the message and converting the message into a java map or java list object.
And S3, traversing the java map or java list object and executing the step S1.
And S4, converting the message into a java Element object by using java xml to analyze the message.
And S5, traversing the attributes and the contents of the java elements and executing the step S1.
S6, the result is stored in the result stack in the form of character string.
The use of a method for converting mixed JSON and XML data into two-dimensional arrays comprises the following steps
The method comprises the following steps:
firstly, placing a data packet character string which needs to be analyzed into a universal two-dimensional array for processing into the method, then, carrying out the first step of the method, namely judging whether the character string is judged at the beginning of { "and at the end of" } ", attempting to analyze the character string into an object by using a java JSON analysis tool, if the character string can be analyzed, determining a JSON object, if the character string is judged at the end of" [ "and at the end of" ] ", attempting to analyze the character string into an array by using a java JSON analysis tool, if the character string can be analyzed, determining the JSON array, if the character string can be analyzed, attempting to analyze the character string into the object by using a java xml tool, if the analysis is successful, determining the character string into an xml message, otherwise, carrying out the second step, namely converting the character string into a java map or a java list object by using the java JSON the second step, then carrying out the first step after traversing the java map or java list object, then executing the fourth step of using java xml to analyze the message, converting the message into a java Element object, then executing the fifth step of traversing the attribute and the content of the java Element, finally executing the first step and executing the last step of storing the conversion result into a result stack in a character string mode to finish the conversion work
The method comprises the following operation steps:
when the method is used, firstly, a data packet character string needing to be analyzed into a universal two-dimensional array for processing is placed into the method, then, the first step of the method is carried out, namely, whether the character string is judged at the beginning of { "and at the end of" } ", and the analysis into an object is tried by using a java JSON analysis tool, if the analysis can be carried out, the JSON object is a JSON object, if the judgment is ended at the beginning of [" and at the end of ">", the JSON array is tried, if the analysis is successful, the JSON object is analyzed by using a java xml tool, if the analysis is not successful, the JSON object is analyzed by using a java xml message, otherwise, the character string format content is converted, then, the second step is carried out, namely, the message is analyzed by using java JSON, the java map or java list object is converted, then, the third step is carried out after traversing the java map or java list object, and then executing the fourth step to use the java xml to analyze the message, converting the message into a java Element object, then executing the fifth step to traverse the attribute and the content of the java Element, finally executing the first step and performing the last step to store the conversion result into a result stack in a character string mode to complete the conversion work, and further facilitating the working personnel to process the converted data.
The above-mentioned embodiments, objects, technical solutions and advantages of the present invention are further described in detail, it should be understood that the above-mentioned embodiments are only illustrative of the present invention and are not intended to limit the present invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (2)

1. A method for converting mixed JSON and XML data into a two-dimensional array comprises the following steps:
s1, judging whether the character string ends with "{" beginning and "}", attempting to analyze the character string into an object by using a java JSON analysis tool, if the character string can be analyzed, determining the object as a JSON object, if the character string ends with "[" beginning and "]", attempting to analyze the character string into an array by using the java JSON analysis tool, if the character string can be analyzed, determining the JSON array, if the character string ends with "<" beginning and ">", attempting to analyze the character string into the object by using a java xml tool, if the character string ends with "<" beginning and ">", determining the character string as an xml message, otherwise, converting the character string into character string format content;
s2, using java json to analyze the message and converting the message into a java map or java list object;
s3, traversing the java map or java list object, executing the step S1;
s4, using java xml to analyze the message and converting the message into a java Element object;
s5, traversing the attributes and contents of the java elements, and executing the step S1;
s6, the result is stored in the result stack in the form of character string.
2. Use of a method for converting mixed JSON and XML data into a two-dimensional array, comprising the steps of:
firstly, placing a data packet character string which needs to be analyzed into a universal two-dimensional array for processing into the method, then, carrying out the first step of the method, namely judging whether the character string is judged at the beginning of { "and at the end of" } ", attempting to analyze the character string into an object by using a java JSON analysis tool, if the character string can be analyzed, determining a JSON object, if the character string is judged at the end of" [ "and at the end of" ] ", attempting to analyze the character string into an array by using a java JSON analysis tool, if the character string can be analyzed, determining the JSON array, if the character string can be analyzed, attempting to analyze the character string into the object by using a java xml tool, if the analysis is successful, determining the character string into an xml message, otherwise, carrying out the second step, namely converting the character string into a java map or a java list object by using the java JSON the second step, then carrying out the first step after traversing the java map or java list object, and then executing the fourth step to use the java xml to analyze the message, converting the message into a java Element object, then executing the fifth step to traverse the attribute and the content of the java Element, and finally executing the first step and executing the last step to store the conversion result into a result stack in a character string mode to complete the conversion work.
CN202110238573.8A 2020-11-24 2021-03-04 Method for converting mixed JSON and XML data into two-dimensional array Pending CN112836475A (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011334718 2020-11-24
CN2020113347186 2020-11-24

Publications (1)

Publication Number Publication Date
CN112836475A true CN112836475A (en) 2021-05-25

Family

ID=75934550

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110238573.8A Pending CN112836475A (en) 2020-11-24 2021-03-04 Method for converting mixed JSON and XML data into two-dimensional array

Country Status (1)

Country Link
CN (1) CN112836475A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104331315A (en) * 2014-10-31 2015-02-04 北京思特奇信息技术股份有限公司 Analysis and generation method and system of json object of any level
CN105868167A (en) * 2016-03-11 2016-08-17 浙江工业大学 Naming resolution method for multiple layers of nested json data
CN109857389A (en) * 2019-01-14 2019-06-07 平安科技(深圳)有限公司 Model data generation method, device, computer equipment and storage medium
CN110677427A (en) * 2019-10-08 2020-01-10 山东浪潮商用系统有限公司 Multi-message analysis method
CN111552838A (en) * 2020-03-26 2020-08-18 平安医疗健康管理股份有限公司 Data processing method and device, computer equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104331315A (en) * 2014-10-31 2015-02-04 北京思特奇信息技术股份有限公司 Analysis and generation method and system of json object of any level
CN105868167A (en) * 2016-03-11 2016-08-17 浙江工业大学 Naming resolution method for multiple layers of nested json data
CN109857389A (en) * 2019-01-14 2019-06-07 平安科技(深圳)有限公司 Model data generation method, device, computer equipment and storage medium
CN110677427A (en) * 2019-10-08 2020-01-10 山东浪潮商用系统有限公司 Multi-message analysis method
CN111552838A (en) * 2020-03-26 2020-08-18 平安医疗健康管理股份有限公司 Data processing method and device, computer equipment and storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
JERE_CHEN: "面试官:如果服务器返回的不是JSON", pages 1 - 15, Retrieved from the Internet <URL:https://juejin.cn/post/6856312535894163463> *
阿炜死了: "JS 判断字符串是否是JSON或者XML", pages 1 - 2, Retrieved from the Internet <URL:https://blog.csdn.net/xzwwjl1314/article/details/108323311> *

Similar Documents

Publication Publication Date Title
Hickson et al. Html5
US8683324B2 (en) Dynamic generation of target files from template files and tracking of the processing of target files
US20070016897A1 (en) Methods, apparatus and computer programs for optimized parsing and service invocation
US20020091999A1 (en) XML based script automation
CN104063401B (en) The method and apparatus that a kind of webpage pattern address merges
CA2381251A1 (en) System and method for language extraction and encoding
WO2006009666A1 (en) Efficient queribility and manageability of an xml index with path subsetting
CA2713439A1 (en) Method and apparatus for efficient management of xml documents
CN102662969A (en) Internet information object positioning method based on webpage structure semantic meaning
CN100489862C (en) Marked language archive analytical method, analytical module and user terminal
CN110287163A (en) Security log acquires analytic method, device, equipment and medium
US20040093347A1 (en) Mechanism for comparing content in data structures
CN102411602B (en) Extensive makeup language (XML) parallel speculation analysis method realized on basis of field programmable gate array (FPGA)
US6907565B1 (en) Web-based output writer and editor
JP2008134906A (en) Business process definition generation method, device and program
CN105022667B (en) One kind being based on built-in browser CSS engine parallel methods
CN112836475A (en) Method for converting mixed JSON and XML data into two-dimensional array
CN113608903A (en) Fault management method based on XML language
CN103678341A (en) Database interaction system and method
CN106933844B (en) Construction method of reachability query index facing large-scale RDF data
CN106897287B (en) Webpage release time extraction method and device for webpage release time extraction
CN110909523A (en) Data processing method and device
CN107545008B (en) Data format requirement storage method and device
CN113536762A (en) JSON text comparison method and device
CN105912627A (en) Data search system and method

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