CN108733689A - A kind of comparison method and device of JSON texts - Google Patents

A kind of comparison method and device of JSON texts Download PDF

Info

Publication number
CN108733689A
CN108733689A CN201710252148.8A CN201710252148A CN108733689A CN 108733689 A CN108733689 A CN 108733689A CN 201710252148 A CN201710252148 A CN 201710252148A CN 108733689 A CN108733689 A CN 108733689A
Authority
CN
China
Prior art keywords
text
value
array
key name
key
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.)
Granted
Application number
CN201710252148.8A
Other languages
Chinese (zh)
Other versions
CN108733689B (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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information 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 Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201710252148.8A priority Critical patent/CN108733689B/en
Publication of CN108733689A publication Critical patent/CN108733689A/en
Application granted granted Critical
Publication of CN108733689B publication Critical patent/CN108733689B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present invention provides a kind of comparison method and device of JSON texts, unordered array is compared in JSON texts and JSON that can be unordered to two, and user can be according to different needs, the self-defined attribute that need not be compared, the accuracy of comparison is not only increased, and improves comparison efficiency to a certain extent.The comparison method of JSON texts of the present invention includes:Preserve the configuration information of JSON texts to be compared;The configuration information is used to that the attribute that need not be compared compared in text to be arranged;Parse the JSON texts to be compared, using by the text conversion of JSON formats as the text of Multiway Tree Structure;By the text that the text conversion of the Multiway Tree Structure is key-value pair structure;In conjunction with the configuration information, the text of the key-value pair structure is compared, to obtain comparison result.

Description

A kind of comparison method and device of JSON texts
Technical field
The present invention relates to field of computer technology, more particularly to a kind of the comparison method and device of JSON texts.
Background technology
JSON (JavaScript Object Notation) is a kind of data interchange format of lightweight.It is nowadays As popular data interchange format, it can be used for transmitted data on network format, data memory format etc..With its stream Row, the demand generated around it is also more and more, such as:Whether variant compare two JSON texts.
In the prior art, many texts compare tool, such as:Beyond Compare, Changes, Diff and one A little online comparison tools etc..In the technical solution of the prior art, for the comparison of JSON texts, it is divided into text solution It analyses and does not parse two kinds of situations:
1, JSON texts are not parsed:JSON texts are read line by line, and according to traveling style of writing, this compares, by different row with certain Kind symbol is marked or exports.
2, JSON texts are parsed:JSON after parsing is respectively compared title and value, by different content with Certain symbol or color mark or output.
In realizing process of the present invention, inventor has found that at least there are the following problems in the prior art:
1, out of order comparison problem can not be solved.For example, can not be by " name/value " unanimously, but " name/value " and other " names The inconsistent JSON texts of title/value " sequence are compared.
2, some personalizations can not be carried out relatively.For example, " name/value " that need not be compared can not be ignored.
Invention content
In view of this, the embodiment of the present invention provides a kind of comparison method and device of JSON texts, it can be unordered to two JSON texts and JSON in unordered array be compared, and user self-defined according to different requirements, can not need The attribute of comparison, not only increases the accuracy of comparison, and improves comparison efficiency to a certain extent.
To achieve the above object, according to the first aspect of the invention, a kind of comparison method of JSON texts is provided.
The comparison method of JSON texts of the present invention includes:Preserve the configuration information of JSON texts to be compared;The configuration Information is used to that the attribute that need not be compared compared in text to be arranged;The JSON texts to be compared are parsed, by JSON formats Text conversion be Multiway Tree Structure text;By the text that the text conversion of the Multiway Tree Structure is key-value pair structure;Knot The configuration information is closed, the text of the key-value pair structure is compared, to obtain comparison result.
Optionally, the parsing JSON texts to be compared, using by the text conversion of JSON formats as Multiway Tree Structure Text the step of include:JSON texts are read line by line, and the text of the JSON formats is solved according to following resolution rules Analysis;When reading object, resolution rules include:Element includes three kinds of forms in object:Object object, array array, with And value value;Rule 1:When the element in object is object:The element is parsed into the son section that a type is object Point, while in this child node inner element of repeated resolution, until reading value value elements;Rule 2:When in object When element is array:Element in array is traversed, the element in array includes:Object object and value value:When the member in array When element is value value, which is converted into the child node that type is primitive;When the element in array is object When object, which is converted into the child node that type is object;The element is advised with reading parsing when object again Then parsed;Rule 3:When the element in object is value:The element is parsed into the son section that a type is primitive Point, and terminated with the parsing of this node;When reading array, resolution rules include:When the element in array is value value, The element is converted into the child node that type is primitive;When the element in array is object object, by the element It is converted into the child node that type is object;The element is parsed with resolution rules when reading object again;Work as reading When to value, resolution rules are:The element is parsed into the child node that a type is primitive, and is parsed and is tied with this node Beam.
Optionally, by the text conversion of the Multiway Tree Structure be key-value pair structure text the step of include:From described The root node of multiway tree is traversed respectively to leaf node, by the nodename in the path traversed through by splicing Come, to obtain all pathnames of the multiway tree;Using pathname as a key name of the text, by the pathname The value of path ends leaf node is as the key assignments corresponding to the key name.
Optionally, described using pathname as a key name of the text, by the path ends leaf of the pathname The value of node as corresponding to the key name key assignments the step of include:It searches identical pathname and carries out duplicate removal, by the repetition A key name of the pathname as text, the value of the leaf node of the identical end in path is then formed into array, and will Value in array encodes ascending sequence according to ASII, to obtain the key assignments corresponding to the key name of the pathname;It will remove A key name of each the remaining pathname as text after duplicate paths, the value of the leaf node of each path ends is made For the key assignments corresponding to the key name.
Optionally, configuration information described in the combination text of the key-value pair structure is compared, to be compared As a result the step of includes:Step A:Text more than determination key name quantity;Step B:Obtain one in the text more than key name quantity Key name;Step C:Judge whether key name matches with the attribute in the configuration information, if so, executing step B;Otherwise, it executes Step D;Step D:Identical key name is searched in the text few from key name quantity, if it is found, thening follow the steps E;Otherwise, will Key name is stored in different set of paths;Step E:The key assignments corresponding to key name found in judgment step D whether with step Key assignments in B corresponding to key name is identical, if so, return to step B;Otherwise, key name is stored in different set of paths;Step F: Judge whether different set of paths are empty, show the identical comparison result of text if so, returning;Otherwise, it returns and shows to compare The different comparison result of text.
According to the second aspect of the invention, a kind of comparison device of JSON texts is provided.
The comparison device of JSON texts of the present invention includes:Preserving module, the configuration for preserving JSON texts to be compared Information;The configuration information is used to that the attribute that need not be compared compared in text to be arranged;Parsing module, for parsing described wait for Compare JSON texts, using by the text conversion of JSON formats as the text of Multiway Tree Structure;Conversion module, being used for will be described more The text conversion for pitching tree construction is the text of key-value pair structure;Comparing module is used in conjunction with the configuration information, by the key assignments The text of structure is compared, to obtain comparison result.
Optionally, the parsing module is additionally operable to:JSON texts are read line by line, according to following resolution rules to the JSON The text of format is parsed;When reading object, resolution rules include:Element includes three kinds of forms in object:Object Object, array array and value value;Rule 1:When the element in object is object:The element is parsed into one Type is the child node of object, while in this child node inner element of repeated resolution, being until reading value value elements Only;Rule 2:When the element in object is array:Element in array is traversed, the element in array includes:Object object and Value value:When the element in array is value value, which is converted into the child node that type is primitive;Work as number When element in group is object object, which is converted into the child node that type is object;Again to the element to read Resolution rules when to object are parsed;Rule 3:When the element in object is value:The element is parsed into a type For the child node of primitive, and terminated with the parsing of this node;When reading array, resolution rules include:When in array When element is value value, which is converted into the child node that type is primitive;When the element in array is object When object, which is converted into the child node that type is object;The element is advised with reading parsing when object again Then parsed;When reading value, resolution rules are:The element is parsed into the child node that a type is primitive, And terminated with the parsing of this node.
Optionally, the conversion module is additionally operable to:It is traversed respectively from the root node of the multiway tree to leaf node, The nodename in the path traversed through is stitched together by point, to obtain all pathnames of the multiway tree;By path Name is referred to as a key name of the text, using the value of the path ends leaf node of the pathname as corresponding to the key name Key assignments.
Optionally, the conversion module is additionally operable to:It searches identical pathname and carries out duplicate removal, by the pathname repeated Then the value of the leaf node of the identical end in path is formed array by a referred to as key name of text, and will be in array Value encodes ascending sequence according to ASII, to obtain the key assignments corresponding to the key name of the pathname;Duplicate paths will be removed A key name of each the remaining pathname as text afterwards, using the value of the leaf node of each path ends as corresponding to The key assignments of the key name.
Optionally, the comparing module is additionally operable to obtain comparison result according to following steps:Step A:Determination key name quantity More texts;Step B:Obtain a key name in the text more than key name quantity;Step C:Judge key name whether with the configuration Attribute in information matches, if so, executing step B;Otherwise, step D is executed;Step D:It is looked into the text few from key name quantity Identical key name is looked for, if it is found, thening follow the steps E;Otherwise, key name is stored in different set of paths;Step E:Judge step Whether the key assignments corresponding to key name found in rapid D is identical as the key assignments corresponding to key name in step B, if so, returning Step B;Otherwise, key name is stored in different set of paths;Step F:Judge whether different set of paths are empty, if so, returning It returns and shows the identical comparison result of text;Otherwise, it returns and shows to compare the different comparison result of text.
According to the third aspect of the present invention, a kind of electronic equipment is provided.
The present invention electronic equipment include:One or more processors;Storage device, for storing one or more journeys Sequence, when one or more of programs are executed by one or more of processors so that one or more of processors are real The comparison method of existing JSON texts provided by the invention.
According to the fourth aspect of the present invention, a kind of computer readable storage medium is provided.
The computer readable storage medium of the present invention, is stored thereon with computer program, described program is executed by processor The comparison method of Shi Shixian JSON texts provided by the invention.
One embodiment in foregoing invention has the following advantages that or advantageous effect:The configuration of text is compared due to increasing Information, user need not can to a certain extent improve comparison according to different demands are self-defined to the text attribute of comparison Efficiency;In addition, during comparison, due to being sorted according to setting rule to the structure of arrays in JSON texts, Unordered array is compared in JSON texts and JSON that thus can be unordered to two, and solving can not be by name in text The problem of title/value is consistent, but the inconsistent JSON texts of name/value and other name/values sequence can not be compared, thus The accuracy rate of comparison is improved to a certain extent.
Further effect possessed by above-mentioned non-usual optional mode adds hereinafter in conjunction with specific implementation mode With explanation.
Description of the drawings
Attached drawing does not constitute inappropriate limitation of the present invention for more fully understanding the present invention.Wherein:
Fig. 1 is the structural schematic diagram of the object of JSON texts;
Fig. 2 is the structural schematic diagram of the array of JSON texts;
Fig. 3 is the structural schematic diagram of the value of JSON texts;
Fig. 4 is a kind of schematic diagram of the comparison method of JSON texts according to the ... of the embodiment of the present invention;
Fig. 5 is multiway tree node structure schematic diagram;
Fig. 6 is the Multiway Tree Structure figure obtained after JSON sample texts parse;
Fig. 7 is the flow chart that the text of key-value pair structure is compared;
Fig. 8 is a kind of schematic diagram of the comparison device of JSON texts according to the ... of the embodiment of the present invention;
Fig. 9 is the hardware configuration signal of the electronic equipment of the comparison method of the JSON texts for realizing the embodiment of the present invention Figure.
Specific implementation mode
It explains to the exemplary embodiment of the present invention below in conjunction with attached drawing, including the various of the embodiment of the present invention Details should think them only exemplary to help understanding.Therefore, those of ordinary skill in the art should recognize It arrives, various changes and modifications can be made to the embodiments described herein, without departing from scope and spirit of the present invention.Together The description to known function and structure is omitted for clarity and conciseness in sample in following description.
It is compared primarily directed to JSON texts in the present invention, JSON texts is simply introduced below.JSON (JavaScript Object Notation) is a kind of data interchange format of lightweight, has become more commonly used data Exchange format can be used for transmitted data on network format, data memory format etc..
JSON is implemented in four kinds of fundamental types (primitive):Character string (string), digital (number), boolean (boolean), empty (null).Two kinds of data structures:
1) object:" name/value " to set, name and value between with ':' (colon) separation, multiple " name/values " is used ', ' (comma) separates.
2) array:The ordered list of multiple values.
JSON has following several formats:
Object (object):Object is unordered " ' name/value ' a to " set.One object is with " { " (left bracket) Start, " " (right parenthesis) end.Each " title " heel one ":" (colon);Use ", " (funny between " ' name/value ' to " Number) separate, as shown in Figure 1.
Array (array):Array is the ordered set of value (value).One array with " [" (left bracket) start, "] " (right bracket) end.", " (comma) is used to separate between value, as shown in Figure 2.
It is worth (value):Can be double quotation marks bracket character string (string), numerical value (number), boolean (true/ False), null, object (object) or array (array).These structures can be nested, as shown in Figure 3.
Technical solution of the present invention is described in detail below.
Fig. 4 is a kind of schematic diagram of the comparison method of JSON texts according to the ... of the embodiment of the present invention.As shown in figure 4, this hair The comparison method of bright JSON texts includes mainly step S40 to S43.
Step S40:Preserve the configuration information of JSON texts to be compared.The configuration information being previously mentioned in this step is for setting Set the attribute that need not be compared compared in text;Such as some attributes shown in table 1, user pass through in this configuration information table Middle setting configuration information, it is self-defined to ignore the attribute for needing to compare, to improve the efficiency of text comparison to a certain extent.
Table 1 compares text configuration information table
Attribute-name Type Meaning
ignorePath Set<String> The set of paths to be ignored
ignorePathPattern Set<String> The path regular expression set to be ignored
ignoreBlank boolean(true/false) Whether space is ignored
ignoreNull boolean(true/false) Whether Null value is ignored
Step S41:Parse the JSON texts to be compared, using by the text conversion of JSON formats as the text of Multiway Tree Structure This.Due to object (object) type of JSON be can be with multilayer nest, and multiway tree can be good at indicating this relationship, because And it is first Multiway Tree Structure by JSON text conversions.JSON texts are read line by line, according to following resolution rules to the JSON The text of format is parsed;
When reading object, element includes three kinds of forms in object:Object object, array array and value value;Three kinds of forms have different identifiers, thus, when reading JSON texts encounter different forms line by line, pass through Rule corresponding to different form is parsed, and resolution rules include:
Rule 1:When the element in object is object:The element is parsed into the child node that a type is object, Simultaneously in this child node inner element of repeated resolution, until reading value value elements;
Rule 2:When the element in object is array:Element in array is traversed, the element in array includes:Object Object and value value:
When the element in array is value value, which is converted into the child node that type is primitive;
When the element in array is object object, which is converted into the child node that type is object;It is right again The element is parsed with resolution rules when reading object;
Rule 3:When the element in object is value:The element is parsed into the son section that a type is primitive Point, and terminated with the parsing of this node;
When reading array, resolution rules include:
When the element in array is value value, which is converted into the child node that type is primitive;
When the element in array is object object, which is converted into the child node that type is object;It is right again The element is parsed with resolution rules when reading object;
When reading value, resolution rules are:
The element is parsed into the child node that a type is primitive, and is terminated with the parsing of this node.
By the parsing of above step, the conversion of the Multiway Tree Structure of JSON texts is realized.Each multi-fork tree node is deposited There is following information:Name (title), type (type, including:Object, array, primitive), data structure (map, Array, value), as shown in Figure 5.
By taking following JSON texts as an example:
Multiway tree after it is parsed is as shown in Figure 6.
Step S42:By the text that the text conversion of the Multiway Tree Structure is key-value pair structure.In this step, from institute The root node for stating multiway tree is traversed respectively to leaf node, by the nodename in the path traversed through by splicing Come, to obtain all pathnames of the multiway tree;It searches identical pathname and carries out duplicate removal, by the pathname repeated As a key name of text, the value of the leaf node of the identical end in path is then formed into array, and by the value in array Ascending sequence is encoded according to ASII, to obtain the key assignments corresponding to the key name of the pathname;After duplicate paths being removed A key name of each the remaining pathname as text, using the value of the leaf node of each path ends as corresponding to this The key assignments of key name.Such as the path toy.name in Fig. 6, a key name of the path as text, the key corresponding to the key name Value is [Minions, Thomas].
Step S43:In conjunction with the configuration information, the text of the key-value pair structure is compared, to obtain comparing knot Fruit.After two texts to be compared are respectively converted into the text of key-value pair structure, configuration information described in the combination will The text of the key-value pair structure is compared, and to obtain comparison result the step of includes:
Step S431:Text more than determination key name quantity;
Step S432:Obtain a key name in the text more than key name quantity;
Step S433:Judge whether key name matches with the attribute in the configuration information, if so, executing step S432; Otherwise, step S434 is executed;
Step S434:Identical key name is searched in the text few from key name quantity, if it is found, thening follow the steps 435;It is no Then, key name is stored in different set of paths;
Step S435:The key assignments corresponding to key name found in judgment step S434 whether with key name in step S432 Corresponding key assignments is identical, if so, return to step S432;Otherwise, key name is stored in different set of paths;
Step S436:Judge whether different set of paths are empty, show the identical comparison result of text if so, returning; Otherwise, it returns and shows to compare the different comparison result of text.
The execution flow chart of above-mentioned implementation procedure is as shown in Figure 7.The configuration information that text is compared by combining, being capable of basis The path for needing setting that need not compare, to improve the efficiency of text comparison to a certain extent.
Fig. 8 is a kind of schematic diagram of the comparison device of JSON texts according to the ... of the embodiment of the present invention.As shown in figure 8, this hair The comparison device 80 of the JSON texts of bright embodiment includes mainly:Preserving module 81, parsing module 82, conversion module 83 and Comparing module 84;Preserving module 81 is used to preserve the configuration information of JSON texts to be compared;The configuration information is for being arranged ratio To the attribute that need not be compared in text;Parsing module 82 is for parsing the JSON texts to be compared, by JSON formats Text conversion be Multiway Tree Structure text;Conversion module 83 is used to the text conversion of the Multiway Tree Structure be key assignments To the text of structure;Comparing module 84 is used to, in conjunction with the configuration information, the text of the key-value pair structure be compared, To obtain comparison result.
The parsing module 82 of the comparison device 80 of JSON texts can be additionally used in:JSON texts are read line by line, according to following solution Analysis rule parses the text of the JSON formats;When reading object, resolution rules include:Element includes in object Three kinds of forms:Object object, array array and value value;Rule 1:When the element in object is object:It should Element is parsed into the child node that a type is object, while in this child node inner element of repeated resolution, until reading Until value value elements;Rule 2:When the element in object is array:Element in array is traversed, the element in array includes: Object object and value value:When the element in array is value value, it is primitive's which, which is converted into type, Child node;When the element in array is object object, which is converted into the child node that type is object;Again to this Element is parsed with resolution rules when reading object;Rule 3:When the element in object is value:The element is parsed Terminate at the child node that a type is primitive, and with the parsing of this node;When reading array, resolution rules include: When the element in array is value value, which is converted into the child node that type is primitive;When the member in array When element is object object, which is converted into the child node that type is object;When again to the element reading object Resolution rules parsed;When reading value, resolution rules are:It is primitive that the element, which is parsed into a type, Child node, and with this node parsing terminate.
The conversion module 83 of the comparison device 80 of JSON texts can be additionally used in:From the root node of the multiway tree to leaf section Point is traversed respectively, and the nodename in the path traversed through is stitched together by point, all to obtain the multiway tree Pathname;Using pathname as a key name of the text, the value of the path ends leaf node of the pathname is made For the key assignments corresponding to the key name.
The conversion module 83 of the comparison device 80 of JSON texts can be additionally used in:It searches identical pathname and carries out duplicate removal, Using the pathname repeated as a key name of text, the value of the leaf node of the identical end in path is then formed into number Group, and the value in array is encoded into ascending sequence according to ASII, to obtain the key corresponding to the key name of the pathname Value;Using each remaining pathname after removing duplicate paths as a key name of text, by the leaf of each path ends The value of node is as the key assignments corresponding to the key name.
The comparing module 84 of the comparison device 80 of JSON texts can also be used to obtain comparison result according to following steps:
Step A:Text more than determination key name quantity;
Step B:Obtain a key name in the text more than key name quantity;
Step C:Judge whether key name matches with the attribute in the configuration information, if so, executing step B;Otherwise, it holds Row step D;
Step D:Identical key name is searched in the text few from key name quantity, if it is found, thening follow the steps E;Otherwise, will Key name is stored in different set of paths;
Step E:The key assignments corresponding to key name found in judgment step D whether with corresponding to key name in step B Key assignments is identical, if so, return to step B;Otherwise, key name is stored in different set of paths;
Step F:Judge whether different set of paths are empty, show the identical comparison result of text if so, returning;It is no Then, it returns and shows to compare the different comparison result of text.
According to an embodiment of the invention, the present invention also provides a kind of electronic equipment and a kind of readable storage medium storing program for executing.
The present invention electronic equipment include:One or more processors;Storage device, for storing one or more journeys Sequence, when one or more of programs are executed by one or more of processors so that one or more of processors are real The comparison method of existing JSON texts provided by the invention.
Below with reference to Fig. 9, it illustrates the computer systems 900 suitable for the terminal device for realizing the embodiment of the present application Structural schematic diagram.Terminal device shown in Fig. 9 is only an example, to the function of the embodiment of the present application and should not use model Shroud carrys out any restrictions.
As shown in figure 9, computer system 900 includes central processing unit (CPU) 901, it can be read-only according to being stored in Program in memory (ROM) 902 is loaded into the program in random access storage device (RAM) 903 from storage section 908 And execute various actions appropriate and processing.In RAM 903, also it is stored with system 900 and operates required various program sum numbers According to.CPU901, ROM 902 and RAM 903 are connected with each other by bus 904.Input/output (I/O) interface 905 also connects To bus 904.
It is connected to I/O interfaces 905 with lower component:Importation 906 including keyboard, mouse etc.;It is penetrated including such as cathode The output par, c 907 of spool (CRT), liquid crystal display (LCD) etc. and loud speaker etc.;Storage section 908 including hard disk etc.; And the communications portion 909 of the network interface card including LAN card, modem etc..Communications portion 909 via such as because The network of spy's net executes communication process.Driver 910 is also according to needing to be connected to I/O interfaces 905.Detachable media 911, such as Disk, CD, magneto-optic disk, semiconductor memory etc. are mounted on driver 910, as needed in order to be read from thereon Computer program be mounted into storage section 908 as needed.
Particularly, according to embodiment disclosed by the invention, the comparison process of the JSON texts described in technical solution can To be implemented as computer software programs.For example, embodiment of the disclosure includes a kind of computer program product comprising carrying Computer program on a computer-readable medium, the computer program include the journey of the comparison method for executing JSON texts Sequence code.In such embodiments, which can be downloaded and installed by communications portion 909 from network, And/or it is mounted from detachable media 911.When the computer program is executed by central processing unit (CPU) 901, sheet is executed The above-mentioned function of being limited in the system of application.
It should be noted that computer-readable medium shown in the application can be computer-readable signal media or meter Calculation machine readable storage medium storing program for executing either the two arbitrarily combines.Computer readable storage medium for example can be --- but not Be limited to --- electricity, magnetic, optical, electromagnetic, infrared ray or semiconductor system, device or device, or arbitrary above combination.Meter The more specific example of calculation machine readable storage medium storing program for executing can include but is not limited to:Electrical connection with one or more conducting wires, just It takes formula computer disk, hard disk, random access storage device (RAM), read-only memory (ROM), erasable type and may be programmed read-only storage Device (EPROM or flash memory), optical fiber, portable compact disc read-only memory (CD-ROM), light storage device, magnetic memory device, Or above-mentioned any appropriate combination.In this application, can be any include computer readable storage medium or storage journey The tangible medium of sequence, the program can be commanded the either device use or in connection of execution system, device.And at this In application, computer-readable signal media may include in a base band or as the data-signal that a carrier wave part is propagated, Wherein carry computer-readable program code.Diversified forms may be used in the data-signal of this propagation, including but unlimited In electromagnetic signal, optical signal or above-mentioned any appropriate combination.Computer-readable signal media can also be that computer can Any computer-readable medium other than storage medium is read, which can send, propagates or transmit and be used for By instruction execution system, device either device use or program in connection.Include on computer-readable medium Program code can transmit with any suitable medium, including but not limited to:Wirelessly, electric wire, optical cable, RF etc. or above-mentioned Any appropriate combination.
Flow chart in attached drawing and block diagram, it is illustrated that according to the system of the various embodiments of the application, method and computer journey The architecture, function and operation in the cards of sequence product.In this regard, each box in flowchart or block diagram can generation A part for a part for one module, program segment, or code of table, above-mentioned module, program segment, or code includes one or more Executable instruction for implementing the specified logical function.It should also be noted that in some implementations as replacements, institute in box The function of mark can also occur in a different order than that indicated in the drawings.For example, two boxes succeedingly indicated are practical On can be basically executed in parallel, they can also be executed in the opposite order sometimes, this is depended on the functions involved.Also it wants It is noted that the combination of each box in block diagram or flow chart and the box in block diagram or flow chart, can use and execute rule The dedicated hardware based systems of fixed functions or operations is realized, or can use the group of specialized hardware and computer instruction It closes to realize.
Being described in module involved in the embodiment of the present application can be realized by way of software, can also be by hard The mode of part is realized.Described module can also be arranged in the processor, for example, can be described as:A kind of processor packet Include preserving module 81, parsing module 82, conversion module 83 and comparing module 84.Wherein, the title of these modules is in certain feelings The restriction to the unit itself is not constituted under condition, for example, comparing module, is used in conjunction with the configuration information, by the key assignments The text of structure is compared, to obtain comparison result.
As on the other hand, present invention also provides a kind of computer-readable medium, which can be Included in equipment described in above-described embodiment;Can also be individualism, and without be incorporated the equipment in.Above-mentioned calculating Machine readable medium carries one or more program, when said one or multiple programs are executed by the equipment, makes Obtaining the equipment includes:Preserve the configuration information of JSON texts to be compared;The configuration information compares in text not for being arranged Need the attribute compared;Parse the JSON texts to be compared, using by the text conversion of JSON formats as the text of Multiway Tree Structure This;By the text that the text conversion of the Multiway Tree Structure is key-value pair structure;In conjunction with the configuration information, by the key-value pair The text of structure is compared, to obtain comparison result.
The said goods can perform the method that the embodiment of the present invention is provided, and has the corresponding function module of execution method and has Beneficial effect.The not technical detail of detailed description in the present embodiment, reference can be made to the method that the embodiment of the present invention is provided.
Technical solution according to the ... of the embodiment of the present invention compares the configuration information of text due to increasing, and user can basis Different demands are self-defined to improve the efficiency of comparison to a certain extent to the text attribute of comparison;In addition, comparing During, due to being sorted according to setting rule to the structure of arrays in JSON texts, it is thus possible to unordered to two JSON texts and JSON in unordered array be compared, solving can not be consistent by name/value in text, but name/value The problem of inconsistent JSON texts can not be compared with other name/values sequence, thus ratio is improved to a certain extent To accuracy rate.
Above-mentioned specific implementation mode, does not constitute limiting the scope of the invention.Those skilled in the art should be bright It is white, design requirement and other factors are depended on, various modifications, combination, sub-portfolio and replacement can occur.It is any Modifications, equivalent substitutions and improvements made by within the spirit and principles in the present invention etc., should be included in the scope of the present invention Within.

Claims (12)

1. a kind of comparison method of JSON texts, which is characterized in that including:
Preserve the configuration information of JSON texts to be compared;The configuration information is used to be arranged need not compare in comparison text Attribute;
Parse the JSON texts to be compared, using by the text conversion of JSON formats as the text of Multiway Tree Structure;
By the text that the text conversion of the Multiway Tree Structure is key-value pair structure;
In conjunction with the configuration information, the text of the key-value pair structure is compared, to obtain comparison result.
2. according to the method described in claim 1, it is characterized in that, described parse the JSON texts to be compared, by JSON The text conversion of format be Multiway Tree Structure text the step of include:
JSON texts are read line by line, and the text of the JSON formats is parsed according to following resolution rules;
When reading object, resolution rules include:
Element includes three kinds of forms in object:Object object, array array and value value;
Rule 1:When the element in object is object:The element is parsed into the child node that a type is object, simultaneously In this child node inner element of repeated resolution, until reading value value elements;
Rule 2:When the element in object is array:Element in array is traversed, the element in array includes:Object object and Value value:
When the element in array is value value, which is converted into the child node that type is primitive;
When the element in array is object object, which is converted into the child node that type is object;Again to this yuan Element is parsed with resolution rules when reading object;
Rule 3:When the element in object is value:The element is parsed into a type as the child node of primitive, and with The parsing of this node terminates;
When reading array, resolution rules include:
When the element in array is value value, which is converted into the child node that type is primitive;
When the element in array is object object, which is converted into the child node that type is object;Again to this yuan Element is parsed with resolution rules when reading object;
When reading value, resolution rules are:
The element is parsed into the child node that a type is primitive, and is terminated with the parsing of this node.
3. according to the method described in claim 1, it is characterized in that, being key-value pair knot by the text conversion of the Multiway Tree Structure The step of text of structure includes:
It is traversed respectively from the root node of the multiway tree to leaf node, the nodename in the path traversed through is passed through Point is stitched together, to obtain all pathnames of the multiway tree;
Using pathname as a key name of the text, using the value of the path ends leaf node of the pathname as correspondence In the key assignments of the key name.
4. according to the method described in claim 3, it is characterized in that, described using pathname as a key name of the text, Include using the value of the path ends leaf node of the pathname as the step of key assignments corresponding to the key name:
It searches identical pathname and carries out duplicate removal, using the pathname repeated as a key name of text, then by road The value of the leaf node of the identical end of diameter forms array, and the value in array is encoded ascending sequence according to ASII, with Obtain the key assignments corresponding to the key name of the pathname;
Using each remaining pathname after removing duplicate paths as a key name of text, by the leaf of each path ends The value of node is as the key assignments corresponding to the key name.
5. according to the method described in claim 1, it is characterized in that, configuration information described in the combination, by the key-value pair knot The text of structure is compared, and to obtain comparison result the step of includes:
Step A:Text more than determination key name quantity;
Step B:Obtain a key name in the text more than key name quantity;
Step C:Judge whether key name matches with the attribute in the configuration information, if so, executing step B;Otherwise, step is executed Rapid D;
Step D:Identical key name is searched in the text few from key name quantity, if it is found, thening follow the steps E;Otherwise, by key name It is stored in different set of paths;
Step E:The key assignments corresponding to key name found in judgment step D whether with the key assignments corresponding to key name in step B It is identical, if so, return to step B;Otherwise, key name is stored in different set of paths;
Step F:Judge whether different set of paths are empty, show the identical comparison result of text if so, returning;Otherwise, it returns It returns and shows to compare the different comparison result of text.
6. a kind of comparison device of JSON texts, which is characterized in that including:
Preserving module, the configuration information for preserving JSON texts to be compared;The configuration information is compared for being arranged in text The attribute that need not be compared;
Parsing module, for parsing the JSON texts to be compared, using by the text conversion of JSON formats as Multiway Tree Structure Text;
Conversion module, for the text by the text conversion of the Multiway Tree Structure for key-value pair structure;
Comparing module, in conjunction with the configuration information, the text of the key-value pair structure to be compared, to obtain comparing knot Fruit.
7. device according to claim 6, which is characterized in that the parsing module is additionally operable to:
JSON texts are read line by line, and the text of the JSON formats is parsed according to following resolution rules;
When reading object, resolution rules include:
Element includes three kinds of forms in object:Object object, array array and value value;
Rule 1:When the element in object is object:The element is parsed into the child node that a type is object, simultaneously In this child node inner element of repeated resolution, until reading value value elements;
Rule 2:When the element in object is array:Element in array is traversed, the element in array includes:Object object and Value value:
When the element in array is value value, which is converted into the child node that type is primitive;
When the element in array is object object, which is converted into the child node that type is object;Again to this yuan Element is parsed with resolution rules when reading object;
Rule 3:When the element in object is value:The element is parsed into a type as the child node of primitive, and with The parsing of this node terminates;
When reading array, resolution rules include:
When the element in array is value value, which is converted into the child node that type is primitive;
When the element in array is object object, which is converted into the child node that type is object;Again to this yuan Element is parsed with resolution rules when reading object;
When reading value, resolution rules are:
The element is parsed into the child node that a type is primitive, and is terminated with the parsing of this node.
8. device according to claim 6, which is characterized in that the conversion module is additionally operable to:
It is traversed respectively from the root node of the multiway tree to leaf node, the nodename in the path traversed through is passed through Point is stitched together, to obtain all pathnames of the multiway tree;
Using pathname as a key name of the text, using the value of the path ends leaf node of the pathname as correspondence In the key assignments of the key name.
9. device according to claim 8, which is characterized in that the conversion module is additionally operable to:
It searches identical pathname and carries out duplicate removal, using the pathname repeated as a key name of text, then by road The value of the leaf node of the identical end of diameter forms array, and the value in array is encoded ascending sequence according to ASII, with Obtain the key assignments corresponding to the key name of the pathname;
Using each remaining pathname after removing duplicate paths as a key name of text, by the leaf of each path ends The value of node is as the key assignments corresponding to the key name.
10. device according to claim 6, which is characterized in that the comparing module is additionally operable to be obtained according to following steps Comparison result:
Step A:Text more than determination key name quantity;
Step B:Obtain a key name in the text more than key name quantity;
Step C:Judge whether key name matches with the attribute in the configuration information, if so, executing step B;Otherwise, step is executed Rapid D;
Step D:Identical key name is searched in the text few from key name quantity, if it is found, thening follow the steps E;Otherwise, by key name It is stored in different set of paths;
Step E:The key assignments corresponding to key name found in judgment step D whether with the key assignments corresponding to key name in step B It is identical, if so, return to step B;Otherwise, key name is stored in different set of paths;
Step F:Judge whether different set of paths are empty, show the identical comparison result of text if so, returning;Otherwise, it returns It returns and shows to compare the different comparison result of text.
11. a kind of electronic equipment, which is characterized in that including:One or more processors;Storage device, for store one or Multiple programs, when one or more of programs are executed by one or more of processors so that one or more of places Manage method of the device realization as described in any in claim 1-5.
12. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that described program is handled The method as described in any in claim 1-5 is realized when device executes.
CN201710252148.8A 2017-04-18 2017-04-18 JSON text comparison method and device Active CN108733689B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710252148.8A CN108733689B (en) 2017-04-18 2017-04-18 JSON text comparison method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710252148.8A CN108733689B (en) 2017-04-18 2017-04-18 JSON text comparison method and device

Publications (2)

Publication Number Publication Date
CN108733689A true CN108733689A (en) 2018-11-02
CN108733689B CN108733689B (en) 2020-12-22

Family

ID=63924686

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710252148.8A Active CN108733689B (en) 2017-04-18 2017-04-18 JSON text comparison method and device

Country Status (1)

Country Link
CN (1) CN108733689B (en)

Cited By (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109460410A (en) * 2018-11-08 2019-03-12 四川长虹电器股份有限公司 By the json data conversion with set membership at the method for tree structure data
CN109683958A (en) * 2018-12-26 2019-04-26 深圳市越疆科技有限公司 Json structure function management method
CN109714418A (en) * 2018-12-27 2019-05-03 北京潘达互娱科技有限公司 The comparison method of interface returned data calculates equipment
CN110516206A (en) * 2019-07-23 2019-11-29 平安科技(深圳)有限公司 File comparison method, device, computer equipment and storage medium
CN111324577A (en) * 2018-12-17 2020-06-23 大唐移动通信设备有限公司 Method and device for reading and writing Yml file
CN111342933A (en) * 2020-02-25 2020-06-26 卓望数码技术(深圳)有限公司 Data transmission method, device and medium
CN111414330A (en) * 2019-01-04 2020-07-14 阿里巴巴集团控股有限公司 Data editing method and system, data processing device and storage medium
CN111506608A (en) * 2020-04-16 2020-08-07 泰康保险集团股份有限公司 Method and device for comparing structured texts
CN111581456A (en) * 2020-05-09 2020-08-25 深圳市卡数科技有限公司 JSON character string comparison method, device, equipment and storage medium
CN111901310A (en) * 2020-07-06 2020-11-06 北京达佳互联信息技术有限公司 Website security testing method and device, electronic equipment and storage medium
CN112905687A (en) * 2021-03-26 2021-06-04 深圳壹账通智能科技有限公司 Data conversion method and device, electronic equipment and storage medium
CN113010230A (en) * 2021-03-26 2021-06-22 广州市百果园网络科技有限公司 Configuration information processing method, device, equipment and storage medium
CN113536762A (en) * 2021-07-15 2021-10-22 中国工商银行股份有限公司 JSON text comparison method and device
CN116011404A (en) * 2022-08-17 2023-04-25 深圳市沃享科技有限公司 Json file reading and writing method based on simplified data format
CN116108235A (en) * 2023-02-20 2023-05-12 上海安博通信息科技有限公司 Path acquisition method and device for tree structure and processing equipment
CN116910631A (en) * 2023-09-14 2023-10-20 深圳市智慧城市科技发展集团有限公司 Array comparison method, device, electronic equipment and readable storage medium
CN117370398A (en) * 2023-11-15 2024-01-09 航天信息(广东)有限公司 Comparison method and device for changing data

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103970728A (en) * 2013-02-01 2014-08-06 中国银联股份有限公司 Comparison method and system for file
CN104036029A (en) * 2014-06-27 2014-09-10 深圳市腾讯计算机系统有限公司 Big data consistency comparison method and system
CN104462322A (en) * 2014-12-01 2015-03-25 北京国双科技有限公司 Method and device for contrasting character strings
US20160085791A1 (en) * 2012-09-06 2016-03-24 Empire Technology Development Llc Tree comparison to manage progressive data store switchover with assured performance
CN105930325A (en) * 2015-11-19 2016-09-07 中国银联股份有限公司 Reverse analysis method and device for file report comparative difference

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160085791A1 (en) * 2012-09-06 2016-03-24 Empire Technology Development Llc Tree comparison to manage progressive data store switchover with assured performance
CN103970728A (en) * 2013-02-01 2014-08-06 中国银联股份有限公司 Comparison method and system for file
CN104036029A (en) * 2014-06-27 2014-09-10 深圳市腾讯计算机系统有限公司 Big data consistency comparison method and system
CN104462322A (en) * 2014-12-01 2015-03-25 北京国双科技有限公司 Method and device for contrasting character strings
CN105930325A (en) * 2015-11-19 2016-09-07 中国银联股份有限公司 Reverse analysis method and device for file report comparative difference

Cited By (24)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109460410A (en) * 2018-11-08 2019-03-12 四川长虹电器股份有限公司 By the json data conversion with set membership at the method for tree structure data
CN111324577B (en) * 2018-12-17 2023-11-17 大唐移动通信设备有限公司 Yml file reading and writing method and device
CN111324577A (en) * 2018-12-17 2020-06-23 大唐移动通信设备有限公司 Method and device for reading and writing Yml file
CN109683958A (en) * 2018-12-26 2019-04-26 深圳市越疆科技有限公司 Json structure function management method
CN109714418A (en) * 2018-12-27 2019-05-03 北京潘达互娱科技有限公司 The comparison method of interface returned data calculates equipment
CN111414330A (en) * 2019-01-04 2020-07-14 阿里巴巴集团控股有限公司 Data editing method and system, data processing device and storage medium
CN111414330B (en) * 2019-01-04 2024-03-22 阿里巴巴集团控股有限公司 Data editing method and system, data processing device and storage medium
CN110516206A (en) * 2019-07-23 2019-11-29 平安科技(深圳)有限公司 File comparison method, device, computer equipment and storage medium
CN111342933B (en) * 2020-02-25 2022-06-07 卓望数码技术(深圳)有限公司 Data transmission method, device and medium
CN111342933A (en) * 2020-02-25 2020-06-26 卓望数码技术(深圳)有限公司 Data transmission method, device and medium
CN111506608A (en) * 2020-04-16 2020-08-07 泰康保险集团股份有限公司 Method and device for comparing structured texts
CN111581456A (en) * 2020-05-09 2020-08-25 深圳市卡数科技有限公司 JSON character string comparison method, device, equipment and storage medium
CN111901310A (en) * 2020-07-06 2020-11-06 北京达佳互联信息技术有限公司 Website security testing method and device, electronic equipment and storage medium
CN112905687A (en) * 2021-03-26 2021-06-04 深圳壹账通智能科技有限公司 Data conversion method and device, electronic equipment and storage medium
CN113010230B (en) * 2021-03-26 2024-02-09 广州市百果园网络科技有限公司 Configuration information processing method, device, equipment and storage medium
CN113010230A (en) * 2021-03-26 2021-06-22 广州市百果园网络科技有限公司 Configuration information processing method, device, equipment and storage medium
CN113536762A (en) * 2021-07-15 2021-10-22 中国工商银行股份有限公司 JSON text comparison method and device
CN116011404A (en) * 2022-08-17 2023-04-25 深圳市沃享科技有限公司 Json file reading and writing method based on simplified data format
CN116108235A (en) * 2023-02-20 2023-05-12 上海安博通信息科技有限公司 Path acquisition method and device for tree structure and processing equipment
CN116108235B (en) * 2023-02-20 2023-11-10 上海安博通信息科技有限公司 Path acquisition method and device for tree structure and processing equipment
CN116910631A (en) * 2023-09-14 2023-10-20 深圳市智慧城市科技发展集团有限公司 Array comparison method, device, electronic equipment and readable storage medium
CN116910631B (en) * 2023-09-14 2024-01-05 深圳市智慧城市科技发展集团有限公司 Array comparison method, device, electronic equipment and readable storage medium
CN117370398A (en) * 2023-11-15 2024-01-09 航天信息(广东)有限公司 Comparison method and device for changing data
CN117370398B (en) * 2023-11-15 2024-05-28 航天信息(广东)有限公司 Comparison method and device for changing data

Also Published As

Publication number Publication date
CN108733689B (en) 2020-12-22

Similar Documents

Publication Publication Date Title
CN108733689A (en) A kind of comparison method and device of JSON texts
CN108171276B (en) Method and apparatus for generating information
CN109739939A (en) The data fusion method and device of knowledge mapping
CN106980508A (en) Method and apparatus for generating the page
CN106503268B (en) Data comparison methods, devices and systems
CN109871311A (en) A kind of method and apparatus for recommending test case
CN109558128A (en) Json data analysis method, device and computer readable storage medium
CN108628830A (en) A kind of method and apparatus of semantics recognition
CN113312108B (en) SWIFT message verification method and device, electronic equipment and storage medium
CN109508177A (en) A kind of real-time computing technique, device, server and storage medium
CN107145532A (en) The real-time analysis and processing method and system of a kind of flow data
CN110515896A (en) Model resource management method, model file production method, device and system
CN107741972A (en) A kind of searching method of picture, terminal device and storage medium
CN107770783A (en) A kind of base station extending capacity reformation Design Method and relevant device
CN105843882A (en) Information matching method and apparatus
CN109903105A (en) A kind of method and apparatus for improving end article attribute
CN109284367A (en) Method and apparatus for handling text
CN106445645A (en) Method and device for executing distributed computation tasks
CN108694194A (en) A kind of method and apparatus of construction data object
WO2011074942A1 (en) System and method of converting data from a multiple table structure into an edoc format
CN108959294A (en) A kind of method and apparatus accessing search engine
CN110175917A (en) The device and method of parameterized graphicsization processing
CN108170683B (en) Method and apparatus for obtaining information
CN110032574A (en) The processing method and processing device of SQL statement
CN113642295B (en) Page typesetting method, device and computer program product

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