Data analysis method and device, electronic equipment and storage medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-13
- Publication Date
- 2026-08-11
AI Technical Summary
[0003]本公开提供一种数据解析方法、装置、电子设备及存储介质,用以解决现有技术中数据解析工具通用性较差的问题
[0031]The technical solution provided in this disclosure offers at least the following advantages: The data parsing device acquires data to be parsed, including multiple characters. Further, the data parsing device traverses multiple characters and, based on the currently traversed character, preset parsing rules, and a first parsing result, performs a current parsing operation on the first parsing result to obtain the current parsing result. Since the preset parsing rules include a mapping relationship between preset character types and character parsing rules; the first parsing result is the parsing result of the data to be parsed before the current character; the first parsing result includes stored key name information, or the first parsing result includes stored key name information and data value information; and the current parsing operation includes whether to store the current character as key name information or data value information, after traversal is complete, the data parsing device can obtain at least one key-value pair of the data to be parsed based on the current parsing result. Compared to the problem of poor versatility of parsing tools in related technologies, this application is no longer limited by the limitations of parsing tools. Through traversal and preset parsing rules, key-value pair information can be successfully extracted from program logs, thereby improving the versatility of the parsing method.
Smart Images

Figure CN116306571B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to a data parsing method, apparatus, electronic device, and storage medium. Background Technology
[0002] However, existing technologies typically utilize specific data parsing tools to parse specific types of data, thereby obtaining key-value pair information. For example, JSONPath can be used to extract key-value pair information from JSON documents, but it cannot extract key-value pair information from program logs. It is evident that in existing methods, a parsing tool can only adapt to a specific data format, while for other data formats, the parsing program usually needs to be rewritten for adaptation, thus exhibiting poor versatility. Summary of the Invention
[0003] This disclosure provides a data parsing method, apparatus, electronic device, and storage medium to address the problem of poor versatility in existing data parsing tools. The technical solution of this disclosure is as follows:
[0004] According to a first aspect of the present disclosure, a data parsing method is provided. The method includes: acquiring data to be parsed from a program log; the data to be parsed includes multiple characters; traversing the multiple characters, and performing a current parsing operation on the first parsing result based on the currently traversed character, a preset parsing rule, and a first parsing result to obtain a current parsing result; the preset parsing rule includes a mapping relationship between preset character types and character parsing rules; the first parsing result is the parsing result of the data to be parsed before the current character; the first parsing result includes stored key name information, or the first parsing result includes stored key name information and data value information; the current parsing operation includes whether to store the current character as key name information or whether to store the current character as data value information; after traversal is completed, obtaining at least one key-value pair of the data to be parsed based on the current parsing result.
[0005] Optionally, the preset character type includes target type and non-target type, where the target type is punctuation or non-punctuation. Based on the currently traversed character, the preset parsing rules, and the first parsing result, the current parsing operation is performed on the first parsing result to obtain the current parsing result, including: if the current character is not a target type, storing the current character as key name information or data value information in the first parsing result to obtain the current parsing result; if the current character is a target type, preprocessing the first parsing result to obtain the current parsing result; the preprocessing includes accumulating the levels of the first parsing result, deleting the preset levels in the first parsing result, determining the array index in the first parsing result as a preset value, deleting the numerical index of the preset levels in the first parsing result, and modifying one or more of the parameter states of the first parsing result.
[0006] Optionally, the first parsing result also includes a first parameter and a second parameter. The initial state of both the first parameter and the second parameter is the first state. The first parameter is used to indicate that when traversing to the next character, the array index of the first parsing result is increased by a preset cumulative value. The second parameter is used to indicate that when traversing to the next character, the next character is stored as data value information.
[0007] Optionally, if the current character is of the target type, the first parsing result is preprocessed to obtain the current parsing result, including: if the current character is the left curly brace in the target type, the level of the current key name in the key name information of the first parsing result is incremented by 1, and the state of the second parameter is set to the first state; if the level of the current key name contains element sequence information and the state of the first parameter is the second state, the element sequence information is accumulated, and the first parameter is set to the first state to obtain the current parsing result.
[0008] Optionally, if the current character is of the target type, the first parsing result is preprocessed to obtain the current parsing result, including: if the current character is the right curly brace in the target type, the hierarchy of the current key name in the key name information of the first parsing result is deleted; if the state of the second parameter is the second state, the state of the second parameter is modified to the first state.
[0009] Optionally, if the current character is of the target type, the first parsing result is preprocessed to obtain the current parsing result, including: if the current character is the left square bracket in the target type, the array index of the current key name in the key name information of the first parsing result is determined to a preset initial value, and the states of the first parameter and the second parameter are both modified to the second state; the array index is used to indicate the position of the current key name in the array.
[0010] Optionally, if the current character is of the target type, the first parsing result is preprocessed to obtain the current parsing result, including: if the current character is the right square bracket in the target type, the array index of the current key name in the key name information of the first parsing result is deleted; if the state of the second parameter is the second state, the state of the second parameter is modified to the first state.
[0011] Optionally, if the current character is of the target type, the first parsing result is preprocessed to obtain the current parsing result, including: if the current character is a comma in the target type, the state of the first parameter is set to the second state; if the key name information of the first parsing result does not contain an array index in the current key name level, the current key name level is deleted, and the state of the second parameter is set to the first state.
[0012] Optionally, if the current character is of the target type, the first parsing result is preprocessed to obtain the current parsing result, including: if the current character is an equal sign in the target type, the state of the second parameter is set to the second state.
[0013] Optionally, if the current character is of the target type, the first parsing result is preprocessed to obtain the current parsing result, including: if the current character is a space character in the target type, the current character is skipped and the next character of the current character is parsed.
[0014] Optionally, the first parameter is the array index accumulation operation parameter, and the second parameter is the data value recording operation parameter. The first state is the off state, and the second state is the on state. When the array index accumulation operation parameter is on, it is used to indicate that when the next character is traversed, the array index of the first parsing result is increased according to the preset accumulation value. When the data value recording operation parameter is on, it is used to indicate that when the next character is traversed, the next character is recorded as data value information.
[0015] Optionally, the data to be parsed includes: data in the format of the first object being equal to the second object enclosed between the left and right curly braces, and key name information in key-value pairs used to represent key name paths.
[0016] According to a second aspect of the present disclosure, a data parsing apparatus is provided, comprising an acquisition unit and a processing unit; the acquisition unit is configured to acquire data to be parsed from a program log; the data to be parsed includes multiple characters; the multiple characters are used to store key information or value information; the processing unit is configured to traverse the multiple characters and, based on the currently traversed character, a preset parsing rule, and a first parsing result, perform a current parsing operation on the first parsing result to obtain a current parsing result; the preset parsing rule includes a mapping relationship between preset character types and character parsing rules; the first parsing result is the parsing result of the data to be parsed before the current character; the first parsing result includes stored key name information, or the first parsing result includes stored key name information and data value information; the current parsing operation includes whether to store the current character as key name information or whether to store the current character as data value information; the processing unit is further configured to, after traversal is completed, obtain at least one key-value pair of the data to be parsed based on the current parsing result.
[0017] Optionally, the processing unit is specifically configured to perform the following: if the current character is not of the target type, the current character is stored as key name information or data value information in the first parsing result to obtain the current parsing result; if the current character is of the target type, the first parsing result is preprocessed to obtain the current parsing result; the preprocessing includes accumulating the levels of the first parsing result, deleting the preset levels in the first parsing result, determining the array index in the first parsing result as a preset value, deleting the numerical index of the preset level in the first parsing result, and modifying one or more of the parameter states of the first parsing result.
[0018] Optionally, the first parsing result also includes a first parameter and a second parameter. The initial state of both the first parameter and the second parameter is the first state. The first parameter is used to indicate that when traversing to the next character, the array index of the first parsing result is increased by a preset cumulative value. The second parameter is used to indicate that when traversing to the next character, the next character is stored as data value information.
[0019] Optionally, the processing unit is specifically configured to perform the following: if the current character is the left curly brace in the target type, increment the level of the current key name in the key name information of the first parsing result by 1, set the state of the second parameter to the first state, and if the level of the current key name contains element sequence information and the state of the first parameter is the second state, then accumulate the element sequence information and set the first parameter to the first state to obtain the current parsing result.
[0020] Optionally, the processing unit is specifically configured to perform the following: if the current character is a closing curly brace in the target type, delete the level of the current key name in the key name information of the first parsing result; if the state of the second parameter is the second state, then modify the state of the second parameter to the first state.
[0021] Optionally, the processing unit is specifically configured to perform the following: when the current character is a left square bracket in the target type, determine the array index of the current key name in the key name information of the first parsing result as a preset initial value, and modify the states of the first parameter and the second parameter to the second state; the array index is used to indicate the position of the current key name in the array.
[0022] Optionally, the processing unit is specifically configured to perform the following: if the current character is a right square bracket in the target type, delete the array index of the current key name in the key name information of the first parsing result; if the state of the second parameter is the second state, then modify the state of the second parameter to the first state.
[0023] Optionally, the processing unit is specifically configured to perform the following: if the current character is a comma in the target type, set the state of the first parameter to the second state; if the key name information of the first parsing result does not contain an array index in the current key name level, delete the current key name level and set the state of the second parameter to the first state.
[0024] Optionally, the processing unit is specifically configured to perform the following: if the current character is an equal sign in the target type, set the state of the second parameter to the second state.
[0025] Optionally, the processing unit is specifically configured to perform the following: if the current character is a space character in the target type, skip the current character and parse the next character after the current character.
[0026] Optionally, the first parameter is the array index accumulation operation parameter, and the second parameter is the data value recording operation parameter. The first state is the off state, and the second state is the on state. When the array index accumulation operation parameter is on, it is used to indicate that when the next character is traversed, the array index of the first parsing result is increased according to the preset accumulation value. When the data value recording operation parameter is on, it is used to indicate that when the next character is traversed, the next character is recorded as data value information.
[0027] Optionally, the data to be parsed includes: data in the format of the first object being equal to the second object enclosed between the left and right curly braces, and key name information in key-value pairs used to represent key name paths.
[0028] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a processor and a memory for storing processor-executable instructions; wherein the processor is configured to execute instructions to implement the data parsing method of the first aspect described above.
[0029] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which instructions are stored, such that when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is able to perform the data parsing method of the first aspect described above.
[0030] According to a fifth aspect of the present disclosure, a computer program product is provided, the computer program product including computer instructions, which, when executed by a processor, implement the data parsing method as described in the first aspect above.
[0031] The technical solution provided in this disclosure offers at least the following advantages: The data parsing device acquires data to be parsed, including multiple characters. Further, the data parsing device traverses multiple characters and, based on the currently traversed character, preset parsing rules, and a first parsing result, performs a current parsing operation on the first parsing result to obtain the current parsing result. Since the preset parsing rules include a mapping relationship between preset character types and character parsing rules; the first parsing result is the parsing result of the data to be parsed before the current character; the first parsing result includes stored key name information, or the first parsing result includes stored key name information and data value information; and the current parsing operation includes whether to store the current character as key name information or data value information, after traversal is complete, the data parsing device can obtain at least one key-value pair of the data to be parsed based on the current parsing result. Compared to the problem of poor versatility of parsing tools in related technologies, this application is no longer limited by the limitations of parsing tools. Through traversal and preset parsing rules, key-value pair information can be successfully extracted from program logs, thereby improving the versatility of the parsing method.
[0032] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0033] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.
[0034] Figure 1 This is a schematic diagram illustrating the structure of a data parsing system according to an exemplary embodiment;
[0035] Figure 2 This is one of the flowcharts illustrating a data parsing method according to an exemplary embodiment;
[0036] Figure 3 This is a second flowchart illustrating a data parsing method according to an exemplary embodiment;
[0037] Figure 4 This is a third flowchart illustrating a data parsing method according to an exemplary embodiment;
[0038] Figure 5 This is a fourth flowchart illustrating a data parsing method according to an exemplary embodiment;
[0039] Figure 6 This is the fifth flowchart illustrating a data parsing method according to an exemplary embodiment;
[0040] Figure 7This is a flowchart illustrating a data parsing method according to an exemplary embodiment, number six.
[0041] Figure 8 This is the seventh flowchart illustrating a data parsing method according to an exemplary embodiment;
[0042] Figure 9 This is the eighth flowchart illustrating a data parsing method according to an exemplary embodiment;
[0043] Figure 10 This is a schematic diagram illustrating the structure of a data parsing apparatus according to an exemplary embodiment;
[0044] Figure 11 This is a schematic diagram of the structure of an electronic device according to an exemplary embodiment. Detailed Implementation
[0045] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0046] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0047] Furthermore, in the description of the embodiments of this disclosure, unless otherwise stated, " / " means "or," for example, A / B can mean A or B. The term "and / or" in this document is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, in the description of the embodiments of this disclosure, "multiple" refers to two or more.
[0048] It should be noted that all user information and data involved in this disclosure are information and data authorized by the user or fully authorized by all parties.
[0049] Before providing a detailed explanation of the embodiments of this disclosure, some related technologies involved in the embodiments of this disclosure will be introduced first.
[0050] A data structure is a collection of data elements that have one or more specific relationships with each other; in other words, it's a collection of data elements with a "structure." The "structure" refers to the relationships between the data elements, and it can be divided into logical structure and storage structure.
[0051] A map is an abstract data structure that can be represented as <attribute name, value>, or key-value pairs. Key-value pair storage is the simplest organizational form of a database. Here, the key represents the identifier of the stored value, and the value is the data to be stored.
[0052] JavaScript (JS) is a lightweight, interpreted or just-in-time (JIT) programming language with a function-first approach.
[0053] JSON (JavaScript Object Notation) is a lightweight data-interchange format that can represent any supported type, such as strings, numbers, objects, and arrays. Among these, objects and arrays are two particularly special and commonly used types.
[0054] Specifically, in JavaScript, objects are enclosed in curly braces {}, and the data structure is a key-value pair structure: {key1: value1, key2: value2, ...}. In object-oriented languages, the key is the object's property, and the value is the corresponding value. Keys can be represented using integers or strings. The value type can be any type. For example, objects can be represented in JavaScript as: {object1}, {object2}.
[0055] In JavaScript, arrays are enclosed in square brackets [], and their data structure is an indexed structure of ["java", "javascript", "vb", ...]. In JavaScript, arrays are a special data type; they can be used like objects with key-value pairs and also with indices. Similarly, the type of the values can be any type. For example, arrays in JavaScript can be represented as: [array1], [array2].
[0056] When using JSON for data conversion or transmission, users can retrieve the corresponding value using the key name. For data with deeper hierarchies, JSONPath can also be used. JSONPath retrieves the corresponding value by defining a path with symbols and keys. It can match the root element using the "$" symbol and match subordinate elements using "." or "[]". For example, for JSON formatted data: {"Shop": {"Books": [{"Category": "Reference Book", "Author": "A", "Title": "Encyclopedia", "Price": "8.95"}]}
[0057] To obtain the price of the first book in the above JSON data, a user can use JSONPath to query the book's "price," thus finding that the price of the first book is 8.95.
[0058] However, in the process of converting or transmitting non-interface type data, such as in program logs, key-value pairs are usually not formatted using JSON but are transmitted directly. In this case, the format transmitted for key-value pairs is {a=b}. Then, for the above JSON format data, the data obtained in the program log will become: {store={books=[{category=reference book, author=A, book title=encyclopedia, price=9.95}}.
[0059] This disclosure defines the aforementioned program log data as key-value equals data. Key-value equals data cannot be formatted using JSON, nor can it be read using JSONPath. Furthermore, there are currently no existing tools that can quickly and directly extract specific key-value pair information from this type of data, making the analysis of such data extremely difficult in daily work.
[0060] To address the aforementioned issues, this disclosure provides a data parsing method that uses a novel approach to parse key-value pair data character by character, performs custom operations on different symbols in the data, and conducts corresponding calculations based on these custom operations. This method extracts key-value pair information from this special format, thereby solving the problem that such data cannot be parsed using technical means.
[0061] The data parsing method provided in this disclosure can be applied to data parsing systems. Figure 1 A schematic diagram of one structure of this data parsing system is shown. For example... Figure 1 As shown, the data parsing system 10 includes a data parsing device 11 and an electronic device 12. The data parsing device 11 is connected to the electronic device 12. The data parsing device 11 and the electronic device 12 can be connected via a wired connection or a wireless connection; this embodiment of the invention does not limit the connection in this way.
[0062] The data parsing device 11 is used to obtain the data to be parsed from the program log, to traverse multiple characters in the data to be parsed, and to perform the current parsing operation on the first parsing result based on the current character being traversed, the preset parsing rule and the first parsing result, so as to obtain the current parsing result.
[0063] The data parsing device 11 can implement the data parsing method of this disclosure embodiment in various electronic devices 12. For example, the electronic device 12 can be a personal computer, a server, etc.
[0064] In different application scenarios, the data parsing device 11 and the electronic device 12 can be independent devices or integrated into the same device. This embodiment of the invention does not make specific limitations in this regard.
[0065] When the data parsing device 11 and the electronic device 12 are integrated into the same device, the data transmission method between the data parsing device 11 and the electronic device 12 is the data transmission between modules within the device. In this case, the data transmission process between the two is the same as that when the data parsing device 11 and the electronic device 12 are independent of each other.
[0066] In the following embodiments provided in this disclosure, the data parsing device 11 and the electronic device 12 are described as being configured independently of each other.
[0067] Figure 2 This is a flowchart illustrating a data parsing method according to some exemplary embodiments. In some embodiments, the above-described data parsing method can be applied to, for example... Figure 1 The data parsing device and electronic equipment shown can also be applied to other similar devices.
[0068] like Figure 2 As shown, the data parsing method provided in this embodiment includes the following steps S201-S203.
[0069] S201, The data parsing device obtains the data to be parsed from the program log.
[0070] The data to be parsed includes multiple characters; these characters are used to store key or value information.
[0071] As one possible implementation, the data parsing device obtains the data to be parsed from the program log in the electronic device.
[0072] It should be noted that the characters in the data to be parsed can be of any type, such as ordinary strings or special characters, such as curly braces, square brackets, commas, equal signs, or spaces.
[0073] Optionally, the data to be parsed includes: data in the format of the first object being equal to the second object enclosed between the left and right curly braces, and key name information in key-value pairs used to represent key name paths.
[0074] For example, the data to be parsed can be: {Key1 = {array1 = [{AKey1 = A11, BKey1 = B12}, {AKey2 = A21, BKey2 = B22}], array2 = [v1, v2, v3]}, Key2 = v12}.
[0075] As can be seen, data in the format where the first object enclosed between the left and right curly braces is equal to the second object, and the key name information in the key-value pair is used to represent data in the form of key-name path, usually hides key-value pair information. Parsing this type of data has high practical value.
[0076] S202, the data parsing device traverses multiple characters, and performs the current parsing operation on the first parsing result based on the current character being traversed, the preset parsing rules, and the first parsing result, to obtain the current parsing result.
[0077] The preset parsing rules include the mapping relationship between preset character types and character parsing rules; the first parsing result is the parsing result of the data to be parsed before the current character; the first parsing result includes the stored key name information, or the first parsing result includes the stored key name information and data value information; the current parsing operation includes whether to store the current character as key name information or whether to store the current character as data value information.
[0078] As one possible implementation, the data parsing device traverses the data to be parsed in the order of each character. Each time a character is traversed, the data parsing device performs the current parsing operation based on the current character, the preset parsing rules, and the first parsing result (i.e., the parsing result of the data parsing device on the traversed characters) to obtain the current parsing result.
[0079] It should be noted that the preset parsing rules are set in advance by the operation and maintenance personnel in the data parsing device. Since the parsing rules include the mapping relationship between preset character types and character parsing rules, when the data parsing device traverses to a current character, the data parsing device can query the character parsing rule corresponding to the current character type according to the parsing rules.
[0080] In some embodiments, the preset character type includes a target type and a non-target type. For example, the target type can be special characters, such as curly braces, square brackets, commas, equal signs, or spaces; the non-target type is non-special characters, such as ordinary strings. Conversely, the target type can also be non-special characters, and the non-target type can also be special characters. This disclosure does not limit the target type and the non-target type.
[0081] Optionally, if the current character encountered during the traversal is not of the target type, the data parsing device stores the current character as key name information or data value information in the first parsing result to obtain the current parsing result.
[0082] For example, if the current character encountered during the traversal is 'e', and the first parsing result is 'K', the data parsing device stores the current character as key name information in the first parsing result to obtain the current parsing result 'Ke'.
[0083] In another example, the current character encountered during the traversal is 1, the first parsing result is v, and the data parsing device stores the current character as data value information in the first parsing result to obtain the current parsing result v1.
[0084] Optionally, if the current character encountered during traversal is of the target type, the data parsing device preprocesses the first parsing result to obtain the current parsing result. This preprocessing includes accumulating the levels of the first parsing result, deleting preset levels from the first parsing result, setting the array indices in the first parsing result to preset values, deleting the numerical indices of preset levels from the first parsing result, and modifying one or more of the parameter states of the first parsing result.
[0085] For example, if the current character encountered during traversal is { and the first parsing result is empty, the data parsing device will increment the level of the first parsing result by 1 to obtain the current parsing result, denoted as $.
[0086] Understandably, setting different parsing rules for different types of characters makes it easier to find the corresponding parsing rule based on the type of the current character during the data parsing process, thus improving the speed of data parsing. For example, if the current character is a regular string, it can be directly stored as a key name or data value in the first parsing result, thereby obtaining the current parsing result.
[0087] S203. After the traversal is completed, the data parsing device obtains at least one key-value pair of the data to be parsed based on the current parsing result.
[0088] As one possible implementation, after traversing all the characters of the data to be parsed, the data parsing device obtains at least one key-value pair of the data to be parsed based on the current parsing result.
[0089] Optionally, the data parsing device stores each key-value pair in the electronic device to obtain a key-value pair lookup table for user viewing. As shown in Table 1, one form of key-value pair lookup table is illustrated, where the first column represents the key name and the second column represents the data value corresponding to each key name.
[0090] Table 1
[0091] Key Value … …
[0092] The technical solution provided in this disclosure offers at least the following advantages: The data parsing device acquires data to be parsed, including multiple characters. Further, the data parsing device traverses multiple characters and, based on the currently traversed character, preset parsing rules, and a first parsing result, performs a current parsing operation on the first parsing result to obtain the current parsing result. Since the preset parsing rules include a mapping relationship between preset character types and character parsing rules; the first parsing result is the parsing result of the data to be parsed before the current character; the first parsing result includes stored key name information, or the first parsing result includes stored key name information and data value information; and the current parsing operation includes whether to store the current character as key name information or data value information, after traversal is complete, the data parsing device can obtain at least one key-value pair of the data to be parsed based on the current parsing result. Compared to the problem of poor versatility of parsing tools in related technologies, this application is no longer limited by the limitations of parsing tools. Through traversal and preset parsing rules, key-value pair information can be successfully extracted from program logs, thereby improving the versatility of the parsing method.
[0093] In one design, the first parsing result also includes a first parameter and a second parameter. The initial state of both the first and second parameters is the first state. The first parameter indicates that the array index of the first parsing result should be increased by a preset cumulative value when traversing to the next character. The second parameter indicates that the next character should be stored as a data value when traversing to the next character. This provides guidance for parsing the next character, facilitating its parsing.
[0094] To obtain the current parsing result, such as Figure 3 As shown, the above-described S202 provided in this embodiment of the present disclosure specifically includes the following S2021:
[0095] S2021. When the current character is the left curly brace in the target type, the data parsing device increments the level of the current key name in the key name information of the first parsing result by 1, sets the state of the second parameter to the first state, and if the level of the current key name contains element sequence information and the state of the first parameter is the second state, then the element sequence information is accumulated, and the first parameter is set to the first state to obtain the current parsing result.
[0096] As one possible implementation, when the data parsing device encounters the current character, it determines the type of the current character. If the current character is a left curly brace within the target type, the data parsing device increments the level of the current key name in the key name information of the first parsing result by 1 and sets the state of the second parameter to the first state. Further, the data parsing device determines whether the level of the current key name in the first parsing result contains element sequence information. If the level of the current key name contains element sequence information and the state of the first parameter is the second state, the data parsing device accumulates the element sequence information and sets the first parameter to the first state, thus obtaining the current parsing result.
[0097] Understandably, this step involves designing an adaptive parsing strategy for the left curly brace, enabling the data parsing device to detect changes in the key name hierarchy when traversing the left curly brace. This allows the device to increment the hierarchy of the current key name in the key name information of the first parsing result by 1 and set the state of the second parameter to the first state.
[0098] Optionally, the first parameter is the array index increment operation parameter (denoted as IndexAdd, IndA), and the second parameter is the data value recording operation parameter (denoted as ValueAdd, ValA). The first state is off, and the second state is on. When the array index increment operation parameter is on, it indicates that the array index of the first parsed result is incremented by a preset increment value when the next character is encountered. When the data value recording operation parameter is on, it indicates that the next character is recorded as data value information when the next character is encountered. Specifically, IndA defaults to False; when on, it is True, meaning the array index will be incremented in the next character check; when off, it is False, meaning the array index remains unchanged in the next character check. ValA defaults to False; when on, it is True, meaning the data value will accumulate in the next character check; when off, it is False, meaning the data value remains unchanged in the next character check.
[0099] For example, for a left curly brace (“{” Left Brace Symbol, denoted as LBS), when the data parsing device encounters a left curly brace, the key level will increase, and the value record will terminate. For example, if the current key is curKey, the following process will be executed after scanning: curKey->curKey., and ValA->False. If the current IndA = True, and the current key level contains an array index, then the index will be incremented by one and IndA = False, that is: if index: curKey[n]->curKey[n+1].
[0100] Understandably, assigning specific forms to the first and second parameters facilitates the data parsing device's identification and execution of the specific instructions they represent. Furthermore, assigning fixed "off" or "on" states to the first and second states provides a unified standard for data parsing.
[0101] In one design, in order to obtain the current parsing result, such as Figure 4 As shown, the above-described S202 provided in this embodiment of the present disclosure specifically includes the following S2022:
[0102] S2022. When the current character is a right curly brace in the target type, the data parsing device deletes the level of the current key name in the key name information of the first parsing result. If the state of the second parameter is the second state, then the state of the second parameter is modified to the first state.
[0103] As one possible implementation, when the data parsing device encounters the current character, it determines the type of the current character. If the current character is a closing curly brace within the target type, the data parsing device removes the current key name's level from the key name information of the first parsing result. Furthermore, the data parsing device determines the state of the second parameter in the first parsing result; if the second parameter's state is the second state, the data parsing device modifies the state of the second parameter to the first state.
[0104] Understandably, this step involves designing an adaptive parsing strategy for the right curly brace, so that when the data parsing device traverses to the right curly brace, it can detect the end of the key name level and delete the current key name level from the key name information in the first parsing result. If the state of the second parameter is the second state, then the state of the second parameter is changed to the first state.
[0105] Optionally, the first parameter is the array index increment operation parameter (denoted as IndexAdd, IndA), and the second parameter is the data value recording operation parameter (denoted as ValueAdd, ValA). The first state is off, and the second state is on. When the array index increment operation parameter is on, it indicates that the array index of the first parsed result is incremented by a preset increment value when the next character is encountered. When the data value recording operation parameter is on, it indicates that the next character is recorded as data value information when the next character is encountered. Specifically, IndA defaults to False; when on, it is True, meaning the array index will be incremented in the next character check; when off, it is False, meaning the array index remains unchanged in the next character check. ValA defaults to False; when on, it is True, meaning the data value will accumulate in the next character check; when off, it is False, meaning the data value remains unchanged in the next character check.
[0106] For example, for a right curly brace (“}” Right Brace Symbol, denoted as RBS), when the data parsing device encounters a right curly brace, it will delete the last level of the key in the current record, and the record of the value will be terminated; for example, if the current key is: lastKey.curKey, after scanning, the following process will be executed: lastKey.curKey->lastKey, and ValA->False.
[0107] In one design, in order to obtain the current parsing result, such as Figure 5 As shown, the above-described S202 provided in this embodiment of the present disclosure specifically includes the following S2023:
[0108] S2023. When the current character is a left square bracket in the target type, the data parsing device determines the array index of the current key name in the key name information of the first parsing result as a preset initial value, and modifies the state of both the first parameter and the second parameter to the second state.
[0109] The array index is used to indicate the position of the current key name in the array.
[0110] As one possible implementation, when the data parsing device encounters the current character, it determines the type of the current character. If the current character is a left square bracket within the target type, the data parsing device sets the array index of the current key name in the key name information of the first parsing result to a preset initial value. Furthermore, the data parsing device modifies the states of both the first and second parameters to the second state.
[0111] Understandably, this step involves designing an adaptive parsing strategy for the left square bracket, so that when the data parsing device traverses to the left square bracket, it can detect the appearance of the array index of the current key name, determine the array index of the current key name in the key name information of the first parsing result as a preset initial value, and modify the states of the first parameter and the second parameter to the second state.
[0112] Optionally, the first parameter is the array index increment operation parameter (denoted as IndexAdd, IndA), and the second parameter is the data value recording operation parameter (denoted as ValueAdd, ValA). The first state is off, and the second state is on. When the array index increment operation parameter is on, it indicates that the array index of the first parsed result is incremented by a preset increment value when the next character is encountered. When the data value recording operation parameter is on, it indicates that the next character is recorded as data value information when the next character is encountered. Specifically, IndA defaults to False; when on, it is True, meaning the array index will be incremented in the next character check; when off, it is False, meaning the array index remains unchanged in the next character check. ValA defaults to False; when on, it is True, meaning the data value will accumulate in the next character check; when off, it is False, meaning the data value remains unchanged in the next character check.
[0113] For example, for a left square bracket (“[”Left Bracket Symbol, denoted as LBkS), when the data parsing device encounters a left square bracket, the level of the key will not increase, but the array index under the key will be increased to the initial value. At the same time, the array index increment symbol is enabled, and the data value accumulation symbol is enabled. For example, if the current key is: curKey, the following process will be executed after scanning: curKey->curKey[-1], while IndA->True, ValA->True.
[0114] In one design, in order to obtain the current parsing result, such as Figure 6 As shown, the above-described S202 provided in this embodiment of the present disclosure specifically includes the following S2024:
[0115] S2024. If the current character is a right square bracket in the target type, the data parsing device deletes the array index of the current key name in the key name information of the first parsing result. If the state of the second parameter is the second state, then the state of the second parameter is modified to the first state.
[0116] As one possible implementation, the data parsing device determines the type of the current character when iterates through it. If the current character is a closing square bracket in the target type, the data parsing device removes the array index of the current key name from the key name information of the first parsing result. Furthermore, if the state of the second parameter is the second state, the data parsing device modifies the state of the second parameter to the first state.
[0117] Understandably, this step involves designing an adaptive parsing strategy for the right square bracket, so that when the data parsing device traverses to the right square bracket, it can detect the end of the array index of the current key name and delete the array index of the current key name in the key name information of the first parsing result. Furthermore, if the state of the second parameter is the second state, then the state of the second parameter is modified to the first state.
[0118] Optionally, the first parameter is the array index increment operation parameter (denoted as IndexAdd, IndA), and the second parameter is the data value recording operation parameter (denoted as ValueAdd, ValA). The first state is off, and the second state is on. When the array index increment operation parameter is on, it indicates that the array index of the first parsed result is incremented by a preset increment value when the next character is encountered. When the data value recording operation parameter is on, it indicates that the next character is recorded as data value information when the next character is encountered. Specifically, IndA defaults to False; when on, it is True, meaning the array index will be incremented in the next character check; when off, it is False, meaning the array index remains unchanged in the next character check. ValA defaults to False; when on, it is True, meaning the data value will accumulate in the next character check; when off, it is False, meaning the data value remains unchanged in the next character check.
[0119] For example, for a right square bracket (“]” Right Bracket Symbol, denoted as RBkS), when the data parsing device encounters a right square bracket, it will delete the last level index of the key in the current record, and the record of the value will be terminated; for example, if the current key is: curKey[n], after scanning, the following process will be executed: curKey[n]->curKey, and ValA->False.
[0120] In one design, in order to obtain the current parsing result, such as Figure 7 As shown, the above-described S202 provided in this embodiment of the present disclosure specifically includes the following S2025:
[0121] S2025. If the current character is a comma in the target type, the data parsing device sets the state of the first parameter to the second state. If the level of the current key name in the key name information of the first parsing result does not contain an array index, the level of the current key name is deleted, and the state of the second parameter is set to the first state.
[0122] As one possible implementation, the data parsing device determines the type of the current character when iterates through it. If the current character is a comma in the target type, the data parsing device sets the state of the first parameter to the second state. Furthermore, if the key name information in the first parsing result does not contain an array index at the current key name level, the data parsing device deletes the current key name level and sets the state of the second parameter to the first state.
[0123] Understandably, this step designs a parsing strategy for comma adaptability, so that when the data parsing device traverses to a comma, it can sense the change in the state of the first parameter and set the state of the first parameter to the second state. Furthermore, if the level of the current key name in the key name information of the first parsing result does not contain an array index, then the level of the current key name is deleted, and the state of the second parameter is set to the first state.
[0124] Optionally, the first parameter is the array index increment operation parameter (denoted as IndexAdd, IndA), and the second parameter is the data value recording operation parameter (denoted as ValueAdd, ValA). The first state is off, and the second state is on. When the array index increment operation parameter is on, it indicates that the array index of the first parsed result is incremented by a preset increment value when the next character is encountered. When the data value recording operation parameter is on, it indicates that the next character is recorded as data value information when the next character is encountered. Specifically, IndA defaults to False; when on, it is True, meaning the array index will be incremented in the next character check; when off, it is False, meaning the array index remains unchanged in the next character check. ValA defaults to False; when on, it is True, meaning the data value will accumulate in the next character check; when off, it is False, meaning the data value remains unchanged in the next character check.
[0125] For example, for a comma (“,” Comma Symbol, denoted as CoS), when the data parsing device encounters a comma, the array index increment symbol is enabled. In addition, it will determine whether the current level contains an array index. If not, the character at the current level is deleted, and the record of the value will be terminated. For example, if the current key is lastKey.curKey, after scanning, the following process will be executed: IndA->True; and if not indexed: lastKey.curKey->lastKey., while ValA->False.
[0126] In one design, in order to obtain the current parsing result, such as Figure 8 As shown, the above-described S202 provided in this embodiment of the present disclosure specifically includes the following S2026:
[0127] S2026. If the current character is an equal sign in the target type, the data parsing device sets the state of the second parameter to the second state.
[0128] As one possible implementation, the data parsing device determines the type of the current character when it iterates through it. If the current character is an equal sign in the target type, the data parsing device sets the state of the second parameter to the second state.
[0129] Understandably, this step involves designing an adaptive parsing strategy for the equal sign, so that when the data parsing device traverses to the equal sign, it can detect the change in the state of the second parameter and set the state of the second parameter to the second state.
[0130] Optionally, the first parameter is the array index increment operation parameter (denoted as IndexAdd, IndA), and the second parameter is the data value recording operation parameter (denoted as ValueAdd, ValA). The first state is off, and the second state is on. When the array index increment operation parameter is on, it indicates that the array index of the first parsed result is incremented by a preset increment value when the next character is encountered. When the data value recording operation parameter is on, it indicates that the next character is recorded as data value information when the next character is encountered. Specifically, IndA defaults to False; when on, it is True, meaning the array index will be incremented in the next character check; when off, it is False, meaning the array index remains unchanged in the next character check. ValA defaults to False; when on, it is True, meaning the data value will accumulate in the next character check; when off, it is False, meaning the data value remains unchanged in the next character check.
[0131] For example, for the equal sign (“=” Equal Symbol, denoted as EqS), when the data parsing device encounters the equal sign, the data value accumulation symbol is turned on, i.e., ValA->True.
[0132] In one design, in order to obtain the current parsing result, such as Figure 9 As shown, the above-described S202 provided in this embodiment of the present disclosure specifically includes the following S2027:
[0133] S2027. If the current character is a space character in the target type, the data parsing device skips the current character and parses the next character.
[0134] As one possible implementation, the data parsing device determines the type of the current character when it encounters it. If the current character is a space character in the target type, the data parsing device skips the current character and parses the next character.
[0135] Understandably, this step involves designing an adaptive parsing strategy for the space character, so that when the data parsing device encounters a space character, it perceives that the current character has no parsing meaning, skips the current character, and directly parses the next character.
[0136] Optionally, the first parameter is the array index increment operation parameter (denoted as IndexAdd, IndA), and the second parameter is the data value recording operation parameter (denoted as ValueAdd, ValA). The first state is off, and the second state is on. When the array index increment operation parameter is on, it indicates that the array index of the first parsed result is incremented by a preset increment value when the next character is encountered. When the data value recording operation parameter is on, it indicates that the next character is recorded as data value information when the next character is encountered. Specifically, IndA defaults to False; when on, it is True, meaning the array index will be incremented in the next character check; when off, it is False, meaning the array index remains unchanged in the next character check. ValA defaults to False; when on, it is True, meaning the data value will accumulate in the next character check; when off, it is False, meaning the data value remains unchanged in the next character check.
[0137] For example, for the whitespace symbol (""Blank Symbol, denoted as BlS), when the data parsing device encounters a whitespace symbol during scanning, it performs a skip operation.
[0138] Optionally, for non-target type characters, if the current IndA = True and the current level contains array indices, increment the array index value of the current level by one, and then turn off the array index increment sign; if the current ValA = True, store the key and accumulate the current value; if the current ValA = False, accumulate the current key but do not store it.
[0139] Suppose we have the following key-value pair data: {"Key1": {"Array1": [{"AKey1:A11", "BKey1:B12"}, {"AKey1":"A21", "BKey1":"BKey1=B22"}], "Array2": ["v1", "v2", "v3"]}, "Key2":"v12"}.
[0140] When passed directly in the program text, it will be stored in the following format:
[0141] {Key1 = {array1 = [{AKey1 = A11, BKey1 = B12}, {AKey2 = A21, BKey2 = B22}], array2 = [v1, v2, v3]}, Key2 = v12}.
[0142] Using the parsing methods described in S2021-S2027 above, the program text was parsed, and the following parsing results were obtained:
[0143] Key name: $.Key1.array1[0].AKey1, Value: A11;
[0144] Key name: $.Key1.array1[0].BKey1, Value: B12;
[0145] Key name: $.Key1.array1[0].AKey2, Value: A21;
[0146] Key name: $.Key1.array1[0].BKey2, Value: B22;
[0147] Key: $.Key1.array2[0], Value: v1;
[0148] Key name: $.Key1.array2[1], Value: v2;
[0149] Key name: $.Key1.array2[2], Value: v3;
[0150] Key name: $.Key2, Value: v12.
[0151] Here, $ represents the default initial character.
[0152] It is understandable that the number of iterations of the data in this disclosure is 1, with a complexity of O(n). During the traversal, data is searched through a hash table, with a complexity of O(1). Data is inserted through a hash table, with a complexity of O(1). In summary, the time complexity of this disclosure is: T(n) = O(n) + O(1) + O(1) = O(n).
[0153] The above embodiments primarily describe the solutions provided by the embodiments of this disclosure from the perspective of an apparatus (device). It is understood that, in order to implement the above methods, the apparatus or device includes hardware structures and / or software modules corresponding to the execution of each method flow, and these hardware structures and / or software modules corresponding to the execution of each method flow can constitute an electronic device. Those skilled in the art should readily recognize that, in conjunction with the algorithm steps of the various examples described in the embodiments disclosed herein, this disclosure can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in a hardware or computer software-driven hardware manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this disclosure.
[0154] This disclosure embodiment can divide the apparatus or device into functional modules according to the above method examples. For example, the apparatus or device can be divided into functional modules corresponding to each function, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this disclosure embodiment is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.
[0155] Figure 10 This is a schematic diagram illustrating the structure of a data parsing apparatus according to an exemplary embodiment. (Refer to...) Figure 10 As shown, the data parsing device 30 provided in this embodiment is applied to a terminal device. The data parsing device 30 includes an acquisition unit 301 and a processing unit 302.
[0156] The acquisition unit 301 is configured to acquire the data to be parsed from the program log; the data to be parsed includes multiple characters; the processing unit 302 is configured to traverse the multiple characters and, based on the currently traversed character, the preset parsing rules, and the first parsing result, perform a current parsing operation on the first parsing result to obtain the current parsing result; the preset parsing rules include the mapping relationship between preset character types and character parsing rules; the first parsing result is the parsing result of the data to be parsed before the current character; the first parsing result includes stored key name information, or the first parsing result includes stored key name information and data value information; the current parsing operation includes whether to store the current character as key name information or whether to store the current character as data value information; the processing unit 302 is also configured to, after the traversal is completed, obtain at least one key-value pair of the data to be parsed based on the current parsing result.
[0157] Optionally, the processing unit 302 is specifically configured to perform the following: if the current character is not of the target type, the current character is stored as key name information or data value information in the first parsing result to obtain the current parsing result; if the current character is of the target type, the first parsing result is preprocessed to obtain the current parsing result; the preprocessing includes accumulating the levels of the first parsing result, deleting the preset levels in the first parsing result, determining the array index in the first parsing result as a preset value, deleting the numerical index of the preset level in the first parsing result, and modifying one or more of the parameter states of the first parsing result.
[0158] Optionally, the first parsing result also includes a first parameter and a second parameter. The initial state of both the first parameter and the second parameter is the first state. The first parameter is used to indicate that when traversing to the next character, the array index of the first parsing result is increased by a preset cumulative value. The second parameter is used to indicate that when traversing to the next character, the next character is stored as data value information.
[0159] Optionally, the processing unit 302 is specifically configured to perform the following: when the current character is the left curly brace in the target type, increment the level of the current key name in the key name information of the first parsing result by 1, set the state of the second parameter to the first state, and if the level of the current key name contains element sequence information and the state of the first parameter is the second state, then accumulate the element sequence information and set the first parameter to the first state to obtain the current parsing result.
[0160] Optionally, the processing unit 302 is specifically configured to perform the following: if the current character is a right curly brace in the target type, delete the level of the current key name in the key name information of the first parsing result; if the state of the second parameter is the second state, then modify the state of the second parameter to the first state.
[0161] Optionally, the processing unit 302 is specifically configured to perform the following: when the current character is a left square bracket in the target type, determine the array index of the current key name in the key name information of the first parsing result as a preset initial value, and modify the states of the first parameter and the second parameter to the second state; the array index is used to indicate the position of the current key name in the array.
[0162] Optionally, the processing unit 302 is specifically configured to perform the following: if the current character is a right square bracket in the target type, delete the array index of the current key name in the key name information of the first parsing result; if the state of the second parameter is the second state, then modify the state of the second parameter to the first state.
[0163] Optionally, the processing unit 302 is specifically configured to perform the following: if the current character is a comma in the target type, set the state of the first parameter to the second state; if the key name information of the first parsing result does not contain an array index in the current key name level, delete the current key name level and set the state of the second parameter to the first state.
[0164] Optionally, processing unit 302 is specifically configured to perform the following: if the current character is an equal sign in the target type, set the state of the second parameter to the second state.
[0165] Optionally, processing unit 302 is specifically configured to perform the following: if the current character is a space character in the target type, skip the current character and parse the next character after the current character.
[0166] Optionally, the first parameter is the array index accumulation operation parameter, and the second parameter is the data value recording operation parameter. The first state is the off state, and the second state is the on state. When the array index accumulation operation parameter is on, it is used to indicate that when the next character is traversed, the array index of the first parsing result is increased according to the preset accumulation value. When the data value recording operation parameter is on, it is used to indicate that when the next character is traversed, the next character is recorded as data value information.
[0167] Optionally, the data to be parsed includes: data in the format of the first object being equal to the second object enclosed between the left and right curly braces, and key name information in key-value pairs used to represent key name paths.
[0168] Figure 11 This is a schematic diagram of the structure of an electronic device provided in this disclosure. For example... Figure 11 The electronic device 40 may include at least one processor 401 and a memory 402 for storing processor-executable instructions, wherein the processor 401 is configured to execute the instructions in the memory 402 to implement the data parsing method in the above embodiments.
[0169] In addition, the electronic device 40 may also include a communication bus 403 and at least one communication interface 404.
[0170] Processor 401 may be a processor (central processing unit, CPU), microprocessor unit, ASIC, or one or more integrated circuits for controlling the execution of programs according to the present disclosure.
[0171] The communication bus 403 may include a path for transmitting information between the aforementioned components.
[0172] Communication interface 404 uses any transceiver-like device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area networks (WLAN), etc.
[0173] Memory 402 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital versatile optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. Memory may exist independently and be connected to the processor via a bus. Memory may also be integrated with the processor.
[0174] The memory 402 stores instructions for executing the present invention, and the processor 401 controls the execution of these instructions. The processor 401 executes the instructions stored in the memory 402 to implement the functions of the data parsing method of this invention.
[0175] As an example, combined Figure 10 The functions implemented by the acquisition unit 301 and the processing unit 302 in the data parsing device 30 are the same as those of the data parsing device 30. Figure 11 The processor 401 in it has the same function.
[0176] In a specific implementation, as one example, processor 401 may include one or more CPUs, for example... Figure 11 CPU0 and CPU1 in the CPU.
[0177] In a specific implementation, as one example, the electronic device 40 may include multiple processors, such as... Figure 11Processors 401 and 407 are described herein. Each of these processors may be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor. A processor here may refer to one or more devices, circuits, and / or processing cores used to process data (e.g., computer program instructions).
[0178] In a specific implementation, as one embodiment, the electronic device 40 may further include an output device 405 and an input device 406. The output device 405 communicates with the processor 401 and can display information in various ways. For example, the output device 405 may be a liquid crystal display (LCD), a light-emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector, etc. The input device 406 communicates with the processor 401 and can accept input from user objects in various ways. For example, the input device 406 may be a mouse, keyboard, touchscreen device, or sensing device, etc.
[0179] Those skilled in the art will understand that Figure 11 The structure shown does not constitute a limitation on the electronic device 40, and may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0180] In addition, this disclosure also provides a computer-readable storage medium that, when the instructions in the computer-readable storage medium are executed by the processor of an electronic device, enables the electronic device to perform the data parsing method provided in the above embodiments.
[0181] In addition, this disclosure also provides a computer program product, including computer instructions, which, when executed on an electronic device, cause the electronic device to perform the data parsing method provided in the above embodiments.
[0182] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the disclosure herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the claims.
Claims
1. A data parsing method, characterized by, The method includes: Obtain the data to be parsed from the program log; the data to be parsed includes multiple characters; the multiple characters are used to store key information or value information; The system iterates through the multiple characters and, based on the currently encountered character, a preset parsing rule, and a first parsing result, performs a current parsing operation on the first parsing result to obtain the current parsing result. The preset parsing rule includes a mapping relationship between preset character types and character parsing rules. The first parsing result is the parsing result of the data to be parsed before the current character. The first parsing result includes stored key name information, or it includes stored key name information and data value information. The first parsing result also includes a first parameter and a second parameter. The first parameter indicates that the array index of the first parsing result is increased by a preset cumulative value when the next character is encountered. The second parameter indicates that the next character is stored as the data value information when the next character is encountered. The initial state of the second parameter is the first state, and the first state is the off state. The current parsing operation includes whether to store the current character as key name information or whether to store the current character as data value information. After the traversal is complete, at least one key-value pair of the data to be parsed is obtained based on the current parsing result; The preset character type includes a target type and a non-target type, wherein the target type is a punctuation mark or a non-punctuation mark; the target type includes at least one of the following: left curly brace, right curly brace, left square bracket, right square bracket, comma, equal sign, and space; the step of performing the current parsing operation on the first parsing result based on the currently traversed character, the preset parsing rule, and the first parsing result to obtain the current parsing result includes: If the current character is of the non-target type, then the current character is stored as the key name information or the data value information in the first parsing result to obtain the current parsing result; If the current character is the target type, then the first parsing result is preprocessed to obtain the current parsing result; the preprocessing includes accumulating the levels of the first parsing result, deleting a preset level from the first parsing result, determining the array index of the first parsing result as a preset value, deleting the numerical index of the preset level in the first parsing result, and modifying one or more of the parameter states of the first parsing result; Specifically, when the current character is an equal sign in the target type, the state of the second parameter is set to a second state; the second state is an on state. The data to be parsed includes: data in the format of a first object equal to a second object enclosed between the left and right curly braces, and the key name information in the key-value pairs is used to represent the key name path.
2. The data parsing method of claim 1, wherein, If the current character is the target type, then the first parsing result is preprocessed to obtain the current parsing result, including: If the current character is a left curly brace in the target type, increment the level of the current key name in the key name information of the first parsing result by 1, set the state of the second parameter to the first state, and if the level of the current key name contains element sequence information and the state of the first parameter is the second state, then accumulate the element sequence information and set the first parameter to the first state to obtain the current parsing result.
3. The data parsing method of claim 1, wherein, If the current character is the target type, then the first parsing result is preprocessed to obtain the current parsing result, including: If the current character is a right curly brace in the target type, delete the level of the current key name in the key name information of the first parsing result. If the state of the second parameter is the second state, then modify the state of the second parameter to the first state.
4. The data parsing method of claim 1, wherein, If the current character is the target type, then the first parsing result is preprocessed to obtain the current parsing result, including: When the current character is a left square bracket in the target type, the array index of the current key name in the key name information of the first parsing result is determined as a preset initial value, and the states of the first parameter and the second parameter are both modified to the second state; the array index is used to indicate the position of the current key name in the array.
5. The data parsing method of claim 1, wherein, If the current character is the target type, then the first parsing result is preprocessed to obtain the current parsing result, including: If the current character is a right square bracket in the target type, delete the array index of the current key name in the key name information of the first parsing result. If the state of the second parameter is the second state, then modify the state of the second parameter to the first state.
6. The data parsing method of claim 1, wherein, If the current character is the target type, then the first parsing result is preprocessed to obtain the current parsing result, including: If the current character is a comma in the target type, the state of the first parameter is set to the second state. If the level of the current key name in the key name information of the first parsing result does not contain an array index, the level of the current key name is deleted, and the state of the second parameter is set to the first state.
7. The data parsing method of claim 1, wherein, If the current character is the target type, then the first parsing result is preprocessed to obtain the current parsing result, including: If the current character is a space character in the target type, then skip the current character and parse the next character.
8. The data parsing method according to any one of claims 1-7, characterized in that, The first parameter is the array index accumulation operation parameter, and the second parameter is the data value recording operation parameter; The array index accumulation operation parameter, in the enabled state, is used to indicate that when traversing to the next character, the array index of the first parsing result is increased by a preset accumulation value; the data value recording operation parameter, in the enabled state, is used to indicate that when traversing to the next character, the next character is recorded as the data value information.
9. A data parsing device, characterized by, The data parsing device includes an acquisition unit and a processing unit; The acquisition unit is configured to acquire data to be parsed from the program log; the data to be parsed includes multiple characters; the multiple characters are used to store key information or value information. The processing unit is configured to traverse the plurality of characters, and based on the currently traversed character, a preset parsing rule, and a first parsing result, perform a current parsing operation on the first parsing result to obtain a current parsing result; the preset parsing rule includes a mapping relationship between preset character types and character parsing rules; The first parsing result is the parsing result of the data to be parsed preceding the current character; The first parsing result includes stored key name information, or the first parsing result includes stored key name information and data value information; the first parsing result also includes a first parameter and a second parameter, the first parameter being used to indicate that when traversing to the next character, the array index of the first parsing result is increased by a preset cumulative value; the second parameter being used to indicate that when traversing to the next character, the next character is stored as the data value information; the initial state of the second parameter is the first state, and the first state is the off state; the current parsing operation includes whether to store the current character as key name information or whether to store the current character as data value information; The processing unit is further configured to perform the following operation after the traversal is completed: obtain at least one key-value pair of the data to be parsed based on the current parsing result. The preset character type includes target type and non-target type. The target type is a punctuation mark or a non-punctuation mark. The target type includes at least one of the following: left curly brace, right curly brace, left square bracket, right square bracket, comma, equal sign, and space. The processing unit is specifically configured to execute: If the current character is of the non-target type, then the current character is stored as the key name information or the data value information in the first parsing result to obtain the current parsing result; If the current character is the target type, then the first parsing result is preprocessed to obtain the current parsing result; The preprocessing includes accumulating the levels of the first parsing result, deleting a preset level from the first parsing result, determining the array index of the first parsing result as a preset value, deleting the numerical index of the preset level in the first parsing result, and modifying one or more of the parameter states of the first parsing result. Specifically, when the current character is an equal sign in the target type, the state of the second parameter is set to a second state; the second state is an on state. The data to be parsed includes: data in the format of a first object equal to a second object enclosed between the left and right curly braces, and the key name information in the key-value pairs is used to represent the key name path.
10. An electronic device, comprising: include: A processor and a memory for storing instructions executable by the processor; wherein the processor is configured to execute instructions to implement the data parsing method of any one of claims 1-8.
11. A computer-readable storage medium having stored thereon instructions, the instructions comprising, When the instructions in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device is able to perform the data parsing method as described in any one of claims 1-8.
Citation Information
Patent Citations
Log data extracting method and device
CN106844505A
Log analysis method, system and equipment
CN110309113A
Analysis method and device for parameters in character string, storage medium and electronic equipment
CN111061482A