A configuration file parsing method, apparatus, device and medium

By parsing the target key-value pairs in the configuration file, determining their data type, and identifying multi-level parent-child relationships, the problem of parsing and assigning complex nested configuration items is solved, achieving accurate and efficient parsing and assignment of configuration files.

CN114995869BActive Publication Date: 2026-04-21JINAN INSPUR DATA TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
JINAN INSPUR DATA TECH CO LTD
Filing Date
2022-05-31
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

Existing technologies struggle to efficiently and accurately parse and assign values ​​to configuration files with complex nested configuration items, affecting the correct execution of programs.

Method used

By parsing the target key-value pairs in the configuration file, the data type is determined. If it is an object type, the multi-level key-value pairs are identified from the storage medium, their parent-child relationships are analyzed, and the combined value is determined. Finally, the value is modified to the combined value.

Benefits of technology

It achieves accurate and efficient parsing and assignment of configuration files, ensuring that the program can execute correctly.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114995869B_ABST
    Figure CN114995869B_ABST
Patent Text Reader

Abstract

The application discloses a configuration file parsing method and device, equipment and medium, comprising: parsing a configuration file to obtain a target key-value pair in the configuration file; judging the data type of the value in the target key-value pair; if the data type of the value is an object type, determining a multi-level key-value pair corresponding to the target key-value pair from a storage medium; analyzing the parent-child relationship of each key-value pair in the multi-level key-value pair, and determining a combined value based on the parent-child relationship; and modifying the value in the target key-value pair to the combined value. In this way, the configuration file can be accurately and efficiently parsed and assigned.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of configuration file parsing technology, and in particular to a configuration file parsing method, apparatus, device and medium. Background Technology

[0002] Configuration files are a crucial file type in project applications; every program needs to define and parse them. Common file types include JSON, INI, property, and YAML. YAML, in particular, is a highly readable and easy-to-understand format used to represent serialized data, employing key-value pairs. Key-value pairs are a commonly used data structure in configuration files, with corresponding data structures and built-in functions for languages ​​like Java, Python, and Go. The correctness of parsing and assigning configuration items determines whether configuration variables can be read correctly and whether the program can execute correctly. Parsing and assigning values ​​to complex nested configuration items is especially important in the configuration file parsing process. Ensuring accurate and efficient parsing of configuration files containing complex nested configuration items is a pressing issue that needs to be addressed. Summary of the Invention

[0003] In view of this, the purpose of this application is to provide a configuration file parsing method, apparatus, device, and medium that can ensure accurate and efficient parsing and assignment of configuration files. The specific solution is as follows:

[0004] Firstly, this application discloses a configuration file parsing method, including:

[0005] The configuration file is parsed to obtain the target key-value pairs in the configuration file;

[0006] Determine the data type of the value in the target key-value pair;

[0007] If the data type of the value is an object type, then the multi-level key-value pairs corresponding to the target key-value pair are determined from the storage medium.

[0008] Analyze the parent-child relationship of each key-value pair in the multi-level key-value pair, and determine the combined value based on the parent-child relationship;

[0009] Modify the value in the target key-value pair to the combined value.

[0010] Optionally, determining the multi-level key-value pairs corresponding to the target key-value pair from the storage medium includes:

[0011] Based on the key value in the target key-value pair, determine the multi-level key-value pairs corresponding to the target key-value pair from the storage medium;

[0012] In this context, the key value of the highest level in the multi-level key-value pair is the same as the key value in the target key-value pair.

[0013] Optionally, the step of analyzing the parent-child relationship of each key-value pair in the multi-level key-value pair and determining the combined value based on the parent-child relationship includes:

[0014] Determine the root node in the multi-level key-value pair structure.

[0015] Find the child nodes of the root node. If the child node has no child nodes, assign the key-value pair of the child node as an object to the key of the root node. If the child node has child nodes, continue to determine the parent-child relationship until a node with no child nodes is found. Determine the combined value based on the parent-child relationship of each key-value pair.

[0016] Optionally, parsing the configuration file to obtain the target key-value pairs in the configuration file includes:

[0017] The configuration file is parsed using a deserialization function to obtain the target key-value pairs in the configuration file.

[0018] Optionally, after modifying the value in the target key-value pair to the combined value, the method further includes:

[0019] The modified target key-value pairs are serialized using a serialization function to obtain a new configuration file.

[0020] Optionally, if the data type of the value in the target key-value pair is a scalar or array, it also includes:

[0021] Search the storage medium for a key-value pair that has the same key value as the target key-value pair.

[0022] Modify the value in the target key-value pair to the value in the found key-value pair.

[0023] Optionally, after parsing the configuration file to obtain the target key-value pairs in the configuration file, the method further includes:

[0024] The value in the target key-value pair is saved as a string.

[0025] Accordingly, determining the data type of the value in the target key-value pair includes:

[0026] The data type of the value in the target key-value pair is determined based on the saved value.

[0027] Secondly, this application discloses a configuration file parsing device, comprising:

[0028] The configuration file parsing module is used to parse the configuration file to obtain the target key-value pairs in the configuration file;

[0029] The data type determination module is used to determine the data type of the value in the target key-value pair.

[0030] A multi-level key-value pair determination module is used to determine, if the data type of the value is an object type, the multi-level key-value pair corresponding to the target key-value pair from the storage medium;

[0031] The combined value determination module is used to analyze the parent-child relationship of each key-value pair in the multi-level key-value pair and determine the combined value based on the parent-child relationship;

[0032] The value modification module is used to modify the value in the target key-value pair to the combined value.

[0033] Optional, multi-level key-value pair determination module, specifically used for:

[0034] Based on the key value in the target key-value pair, determine the multi-level key-value pairs corresponding to the target key-value pair from the storage medium;

[0035] In this context, the key value of the highest level in the multi-level key-value pair is the same as the key value in the target key-value pair.

[0036] Optionally, the combined value determination module is specifically used to: determine the root node in the multi-level key-value pairs, find the child nodes of the root node, if the child node has no child nodes, assign the key-value pair of the child node as an object to the key of the root node, if the child node has child nodes, continue to perform parent-child relationship judgment until a node with no child nodes is found, and determine the combined value based on the parent-child relationship of each key-value pair.

[0037] Optionally, a configuration file parsing module is used to parse the configuration file based on a deserialization function to obtain the target key-value pairs in the configuration file.

[0038] Accordingly, the device also includes a serialization module, specifically used to perform a serialization operation on the modified target key-value pair based on a serialization function after the value modification module modifies the value in the target key-value pair to the combined value, thereby obtaining a new configuration file.

[0039] Optionally, the device further includes:

[0040] The key-value pair lookup module is used to search for a key-value pair in the storage medium that has the same key value as the target key-value pair if the data type determination module determines that the data type of the value in the target key-value pair is a scalar or an array.

[0041] Correspondingly, the value modification module is specifically used to modify the value in the target key-value pair to the value in the found key-value pair.

[0042] Furthermore, the device also includes:

[0043] The storage module is used to save the value of the target key-value pair as a string after parsing the configuration file and obtaining the target key-value pair in the configuration file.

[0044] Correspondingly, the data type determination module is specifically used to determine the data type of the value in the target key-value pair based on the saved value.

[0045] Thirdly, this application discloses an electronic device, including a memory and a processor, wherein:

[0046] The memory is used to store computer programs;

[0047] The processor is used to execute the computer program to implement the aforementioned configuration file parsing method.

[0048] Fourthly, this application discloses a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the aforementioned configuration file parsing method.

[0049] As can be seen, this application parses the configuration file to obtain the target key-value pairs in the configuration file, then determines the data type of the value in the target key-value pairs. If the data type of the value is an object type, it determines the multi-level key-value pairs corresponding to the target key-value pairs from the storage medium, then analyzes the parent-child relationship of each key-value pair in the multi-level key-value pairs, and determines the combined value based on the parent-child relationship. Finally, it modifies the value in the target key-value pairs to the combined value. In other words, this application parses the target key-value pairs in the configuration file. If the target key-value pair is an object type, it determines the multi-level key-value pairs corresponding to the key-value pair from the storage medium. Then, based on the parent-child relationship of each key-value pair in the multi-level key-value pair, it determines the composite key-value pair and assigns a value to the target key-value pair. In this way, by analyzing the parent-child relationship of each key-value pair in the multi-level key-value pair, it can ensure accurate and efficient parsing and assignment of the configuration file. Attached Figure Description

[0050] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0051] Figure 1 This is a flowchart of a configuration file parsing method disclosed in an embodiment of this application;

[0052] Figure 2This is a flowchart of a specific configuration file parsing method disclosed in an embodiment of this application;

[0053] Figure 3 This is a flowchart of a specific configuration file parsing method disclosed in an embodiment of this application;

[0054] Figure 4 This is a flowchart of a specific configuration file parsing method disclosed in an embodiment of this application;

[0055] Figure 5 This is a schematic diagram of a configuration file parsing device disclosed in an embodiment of this application;

[0056] Figure 6 This is a schematic diagram of an electronic device disclosed in an embodiment of this application. Detailed Implementation

[0057] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0058] Key-value pairs are a common data structure in configuration files, with corresponding data structures and built-in functions available for languages ​​such as Java, Python, and Go. The correctness of parsing and assigning configuration items determines whether configuration variables can be read correctly and whether the program can execute correctly. Parsing and assigning values ​​to complex nested configuration items in configuration files is particularly important. Ensuring accurate and efficient parsing of configuration files containing complex nested configuration items is a pressing problem. Therefore, this application provides a configuration file parsing scheme that guarantees accurate and efficient parsing and assignment of values ​​to configuration files.

[0059] See Figure 1 As shown in the figure, this application discloses a configuration file parsing method, including:

[0060] Step S11: Parse the configuration file to obtain the target key-value pairs in the configuration file.

[0061] In a specific implementation, the configuration file can be parsed based on a deserialization function to obtain the target key-value pairs in the configuration file.

[0062] Furthermore, you can first define a parsing data structure object map[string]interface{}, and then use a deserialization function to parse all key-value pairs in the configuration file.

[0063] It should be noted that a configuration file consists of a series of key-value pairs. Parsing the configuration file is to obtain the key value of the configuration file, and modify the value value of the original configuration file according to the key-value pairs in the storage medium, so as to realize the parsing and assignment of the configuration file.

[0064] Step S12: Determine the data type of the value in the target key-value pair.

[0065] In a specific implementation, the value in the target key-value pair can be saved as a string; the data type of the value in the target key-value pair can be determined based on the saved value.

[0066] It's important to note that key-value pairs generally fall into two categories based on their data types: scalar and array forms, where the value is a basic data type such as a string, boolean, integer, floating-point number, null, time, date, or array; and object forms, where values ​​are nested multiple levels, creating new key-value pairs. Of course, even within object forms, values ​​can sometimes be scalars or arrays. Configuration files for these data types are available in YML configuration files.

[0067] Step S13: If the data type of the value is an object type, then determine the multi-level key-value pairs corresponding to the target key-value pair from the storage medium.

[0068] In a specific implementation, based on the key value in the target key-value pair, a multi-level key-value pair corresponding to the target key-value pair is determined from the storage medium; wherein the key value of the highest level in the multi-level key-value pair is the same as the key value in the target key-value pair. The storage medium may store front-end data.

[0069] Step S14: Analyze the parent-child relationship of each key-value pair in the multi-level key-value pair, and determine the combined value based on the parent-child relationship.

[0070] In a specific implementation, the root node in the multi-level key-value pairs can be determined, and the child nodes of the root node can be found. If the child node has no child nodes, the key-value pair of the child node is assigned as an object to the key of the root node. If the child node has child nodes, the parent-child relationship judgment is continued until a node with no child nodes is found, and the combined value is determined based on the parent-child relationship of each key-value pair.

[0071] In other words, each key-value pair in a multi-level key-value pair hierarchy is a node. For example, the root node is key1-value1, its child node is key2-value2, key2-value2's child node is key3-value3, and key3-value3 has no child nodes. The combined value is determined based on the parent-child relationship of each key-value pair: key3-value3 is assigned to key2, and key2-value2 (i.e., key3-value3) is assigned to key1. The value corresponding to key1 is the combined value. Finally, the root node's value is composed of the key-value pairs of all its child nodes and grandchild or great-grandchild nodes.

[0072] Understandably, for object types, data is combined based on the hierarchical key-value pairs in the storage medium, combined with the key values ​​in the configuration file, and then the values ​​are assigned layer by layer. Finally, a complete object is formed and assigned to the value.

[0073] If the data type of the value is an object type, and no multi-level key-value pairs corresponding to the target key-value pair are determined from the storage medium, that is, the determined key-value pairs are not nested, then the value in the determined key-value pair is directly assigned to the key in the target key-value pair, that is, the value in the target key-value pair is modified to the value in the determined key-value pair.

[0074] Step S15: Modify the value in the target key-value pair to the combined value.

[0075] That is, assign the combined value to the key in the target key-value pair.

[0076] Furthermore, the modified target key-value pairs are serialized using a serialization function to obtain a new configuration file.

[0077] As can be seen, this application embodiment parses the configuration file to obtain the target key-value pairs in the configuration file, then determines the data type of the value in the target key-value pairs. If the data type of the value is an object type, the multi-level key-value pairs corresponding to the target key-value pairs are determined from the storage medium. Then, the parent-child relationship of each key-value pair in the multi-level key-value pairs is analyzed, and a combined value is determined based on the parent-child relationship. Finally, the value in the target key-value pairs is modified to the combined value. In other words, the embodiments of this application parse the target key-value pair in the configuration file. If the target key-value pair is an object type, the multi-level key-value pairs corresponding to the key-value pair are determined from the storage medium. Then, based on the parent-child relationship of each key-value pair in the multi-level key-value pair, the composite key-value pair is determined and the target key-value pair is assigned a value. In this way, by analyzing the parent-child relationship of each key-value pair in the multi-level key-value pair, the accurate and efficient parsing and assignment of the configuration file can be guaranteed.

[0078] See Figure 2 As shown in the figure, this application discloses a specific configuration file parsing method, including:

[0079] Step S21: Parse the configuration file to obtain the target key-value pairs in the configuration file.

[0080] For details on the specific implementation of step S21 above, please refer to the content disclosed in the foregoing embodiments, which will not be repeated here.

[0081] Step S22: Determine the data type of the value in the target key-value pair.

[0082] Step S23: If the data type of the value in the target key-value pair is a scalar or an array, search for a key-value pair in the storage medium that has the same key value as the target key-value pair.

[0083] Step S24: Modify the value in the target key-value pair to the value in the found key-value pair.

[0084] For example, see Figure 3 As shown, Figure 3 This is a flowchart illustrating a specific configuration file parsing method disclosed in this application. The configuration file is parsed into key-value pairs using a deserialization function. Each parsed value is stored as a string, and the data type of the value is determined. If it is a scalar or array, the parsed key value is compared with the key value in the storage medium. If the key values ​​are the same, the value in the storage medium is assigned to the key parsed from the configuration file, completing the data update and configuration file generation. Finally, a new configuration file is generated using a serialization function.

[0085] In other words, for basic scalar and array types, this application embodiment can directly assign the value of the corresponding key-value pair in the storage medium as the whole data to the key in the target key-value pair, and then serialize it into a new configuration file.

[0086] Step S25: If the data type of the value is an object type, then determine the multi-level key-value pairs corresponding to the target key-value pair from the storage medium.

[0087] Step S26: Analyze the parent-child relationship of each key-value pair in the multi-level key-value pair, and determine the combined value based on the parent-child relationship.

[0088] Step S27: Modify the value in the target key-value pair to the combined value.

[0089] Furthermore, the modified target key-value pairs are serialized using a serialization function to obtain a new configuration file.

[0090] For example, see Figure 4 As shown, Figure 4This is a flowchart illustrating a specific configuration file parsing method disclosed in this application. The key-value pairs in the configuration file have values ​​of object type. Data analysis is performed on the hierarchical key-value pairs in the storage medium, and then the parent-child relationships of each key-value pair are analyzed. First, the root node (i.e., the highest-level key in a multi-level relationship) is determined. If it is not the root node, the value corresponding to that key is assigned to the key obtained from parsing the configuration file as a new key-value pair. That is, the key-value pairs in the storage medium that correspond to the key-value pairs in the configuration file are determined to be non-nested. If it is the root node, its corresponding child node key-value pairs are found. It is analyzed whether the child node is the parent node of other key-value pairs. If not, the child node key-value pair is assigned as an object to the root node's key. If the child node is still the parent node of other child nodes, the parent-child relationship determination needs to continue looping until the key-value parsing is finally completed. Finally, the value of the root node is composed of the key-value pairs of all child nodes and their grandchildren or great-grandchildren, completing the data update and configuration file. Finally, a new configuration file will be generated using a serialization function.

[0091] As can be seen, this application parses the configuration file to obtain the target key-value pairs in the configuration file. Then, it determines the data type of the value in the target key-value pair. If the data type of the value in the target key-value pair is a scalar or array, it searches for a key-value pair in the storage medium that has the same key value as the target key-value pair, and modifies the value in the target key-value pair to the value of the found key-value pair. If the data type of the value is an object type, it determines the multi-level key-value pairs corresponding to the target key-value pair from the storage medium, analyzes the parent-child relationship of each key-value pair in the multi-level key-value pairs, determines the combined value based on the parent-child relationship, and finally modifies the value in the target key-value pair to the combined value. In this way, it can ensure accurate and efficient automated parsing and assignment of configuration files, whether the configuration file contains complex nested key-value pairs or not.

[0092] See Figure 5As shown in the figure, this application discloses a configuration file parsing device, including:

[0093] The configuration file parsing module 11 is used to parse the configuration file to obtain the target key-value pairs in the configuration file;

[0094] Data type determination module 12 is used to determine the data type of the value in the target key-value pair;

[0095] The multi-level key-value pair determination module 13 is used to determine the multi-level key-value pair corresponding to the target key-value pair from the storage medium if the data type of the value is an object type.

[0096] The combined value determination module 14 is used to analyze the parent-child relationship of each key-value pair in the multi-level key-value pair and determine the combined value based on the parent-child relationship;

[0097] The value modification module 15 is used to modify the value in the target key-value pair to the combined value.

[0098] As can be seen, this application embodiment parses the configuration file to obtain the target key-value pairs in the configuration file, then determines the data type of the value in the target key-value pairs. If the data type of the value is an object type, the multi-level key-value pairs corresponding to the target key-value pairs are determined from the storage medium. Then, the parent-child relationship of each key-value pair in the multi-level key-value pairs is analyzed, and a combined value is determined based on the parent-child relationship. Finally, the value in the target key-value pairs is modified to the combined value. In other words, the embodiments of this application parse the target key-value pair in the configuration file. If the target key-value pair is an object type, the multi-level key-value pairs corresponding to the key-value pair are determined from the storage medium. Then, based on the parent-child relationship of each key-value pair in the multi-level key-value pair, the composite key-value pair is determined and the target key-value pair is assigned a value. In this way, by analyzing the parent-child relationship of each key-value pair in the multi-level key-value pair, the accurate and efficient parsing and assignment of the configuration file can be guaranteed.

[0099] In a specific implementation, the multi-level key-value pair determination module 13 is specifically used for:

[0100] Based on the key value in the target key-value pair, determine the multi-level key-value pairs corresponding to the target key-value pair from the storage medium;

[0101] In this context, the key value of the highest level in the multi-level key-value pair is the same as the key value in the target key-value pair.

[0102] Furthermore, the combined value determination module 14 is specifically used to: determine the root node in the multi-level key-value pairs, find the child nodes of the root node, if the child node has no child nodes, assign the key-value pair of the child node as an object to the key of the root node, if the child node has child nodes, continue to perform parent-child relationship judgment until a node with no child nodes is found, and determine the combined value based on the parent-child relationship of each key-value pair.

[0103] In one specific implementation, the configuration file parsing module 11 is specifically used to parse the configuration file based on the deserialization function to obtain the target key-value pairs in the configuration file.

[0104] Accordingly, the device also includes a serialization module, specifically used for the value modification module 15 to modify the value in the target key-value pair to the combined value, and then perform a serialization operation on the modified target key-value pair based on the serialization function to obtain a new configuration file.

[0105] Furthermore, the device also includes:

[0106] The key-value pair lookup module is used to search for a key-value pair in the storage medium that has the same key value as the target key-value pair if the data type determination module 12 determines that the data type of the value in the target key-value pair is a scalar or an array.

[0107] Correspondingly, the value modification module 15 is specifically used to modify the value in the target key-value pair to the value in the found key-value pair.

[0108] Furthermore, the device also includes:

[0109] The storage module is used to save the value of the target key-value pair as a string after parsing the configuration file and obtaining the target key-value pair in the configuration file.

[0110] Correspondingly, the data type determination module 12 is specifically used to determine the data type of the value in the target key-value pair based on the saved value.

[0111] See Figure 6 As shown in the illustration, this application discloses an electronic device 20, including a processor 21 and a memory 22; wherein, the memory 22 is used to store a computer program; and the processor 21 is used to execute the computer program to implement the following steps:

[0112] The configuration file is parsed to obtain the target key-value pairs in the configuration file; the data type of the value in the target key-value pair is determined; if the data type of the value is an object type, the multi-level key-value pairs corresponding to the target key-value pair are determined from the storage medium; the parent-child relationship of each key-value pair in the multi-level key-value pair is analyzed, and a combined value is determined based on the parent-child relationship; the value in the target key-value pair is modified to the combined value.

[0113] As can be seen, this application embodiment parses the configuration file to obtain the target key-value pairs in the configuration file, then determines the data type of the value in the target key-value pairs. If the data type of the value is an object type, the multi-level key-value pairs corresponding to the target key-value pairs are determined from the storage medium. Then, the parent-child relationship of each key-value pair in the multi-level key-value pairs is analyzed, and a combined value is determined based on the parent-child relationship. Finally, the value in the target key-value pairs is modified to the combined value. In other words, the embodiments of this application parse the target key-value pair in the configuration file. If the target key-value pair is an object type, the multi-level key-value pairs corresponding to the key-value pair are determined from the storage medium. Then, based on the parent-child relationship of each key-value pair in the multi-level key-value pair, the composite key-value pair is determined and the target key-value pair is assigned a value. In this way, by analyzing the parent-child relationship of each key-value pair in the multi-level key-value pair, the accurate and efficient parsing and assignment of the configuration file can be guaranteed.

[0114] In this embodiment, when the processor 21 executes the computer subroutine stored in the memory 22, it can specifically implement the following steps: based on the key value in the target key-value pair, determine the multi-level key-value pair corresponding to the target key-value pair from the storage medium;

[0115] In this context, the key value of the highest level in the multi-level key-value pair is the same as the key value in the target key-value pair.

[0116] In this embodiment, when the processor 21 executes the computer subroutine stored in the memory 22, it can specifically implement the following steps: determine the root node in the multi-level key-value pairs; search for the child nodes of the root node; if the child node has no child nodes, assign the key-value pair of the child node as an object to the key of the root node; if the child node has child nodes, continue to perform parent-child relationship judgment until a node with no child nodes is found, and determine the combined value based on the parent-child relationship of each key-value pair.

[0117] In this embodiment, when the processor 21 executes the computer subroutine stored in the memory 22, it can specifically implement the following steps: parse the configuration file based on the deserialization function to obtain the target key-value pairs in the configuration file.

[0118] In this embodiment, when the processor 21 executes the computer subroutine stored in the memory 22, it can specifically implement the following steps: after modifying the value in the target key-value pair to the combined value, it performs a serialization operation on the modified target key-value pair based on the serialization function to obtain a new configuration file.

[0119] In this embodiment, when the processor 21 executes the computer subroutine stored in the memory 22, it can specifically implement the following steps: if the data type of the value in the target key-value pair is a scalar or an array, search for a key-value pair in the storage medium that has the same key value as the target key-value pair; modify the value in the target key-value pair to the value in the found key-value pair.

[0120] In this embodiment, when the processor 21 executes the computer subroutine stored in the memory 22, it can specifically implement the following steps: after parsing the configuration file and obtaining the target key-value pair in the configuration file, the value in the target key-value pair is saved as a string; the data type of the value in the target key-value pair is determined based on the saved value.

[0121] Furthermore, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk, or optical disk, and the storage method can be temporary storage or permanent storage.

[0122] In addition, the electronic device 20 also includes a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26; wherein, the power supply 23 is used to provide operating voltage for the various hardware devices on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0123] Furthermore, embodiments of this application disclose a computer-readable storage medium for storing a computer program, wherein the computer program, when executed by a processor, performs the following steps:

[0124] The configuration file is parsed to obtain the target key-value pairs in the configuration file; the data type of the value in the target key-value pair is determined; if the data type of the value is an object type, the multi-level key-value pairs corresponding to the target key-value pair are determined from the storage medium; the parent-child relationship of each key-value pair in the multi-level key-value pair is analyzed, and a combined value is determined based on the parent-child relationship; the value in the target key-value pair is modified to the combined value.

[0125] As can be seen, this application embodiment parses the configuration file to obtain the target key-value pairs in the configuration file, then determines the data type of the value in the target key-value pairs. If the data type of the value is an object type, the multi-level key-value pairs corresponding to the target key-value pairs are determined from the storage medium. Then, the parent-child relationship of each key-value pair in the multi-level key-value pairs is analyzed, and a combined value is determined based on the parent-child relationship. Finally, the value in the target key-value pairs is modified to the combined value. In other words, the embodiments of this application parse the target key-value pair in the configuration file. If the target key-value pair is an object type, the multi-level key-value pairs corresponding to the key-value pair are determined from the storage medium. Then, based on the parent-child relationship of each key-value pair in the multi-level key-value pair, the composite key-value pair is determined and the target key-value pair is assigned a value. In this way, by analyzing the parent-child relationship of each key-value pair in the multi-level key-value pair, the accurate and efficient parsing and assignment of the configuration file can be guaranteed.

[0126] In this embodiment, when the computer subroutine stored in the computer-readable storage medium is executed by the processor, the following steps can be specifically implemented: determining the multi-level key-value pairs corresponding to the target key-value pair from the storage medium based on the key value in the target key-value pair;

[0127] In this context, the key value of the highest level in the multi-level key-value pair is the same as the key value in the target key-value pair.

[0128] In this embodiment, when the computer subroutine stored in the computer-readable storage medium is executed by the processor, it can specifically implement the following steps: determine the root node in the multi-level key-value pairs; find the child nodes of the root node; if the child node has no child nodes, assign the key-value pair of the child node as an object to the key of the root node; if the child node has child nodes, continue to perform parent-child relationship judgment until a node with no child nodes is found, and determine the combined value based on the parent-child relationship of each key-value pair.

[0129] In this embodiment, when the computer subroutine stored in the computer-readable storage medium is executed by the processor, the following steps can be specifically implemented: parsing the configuration file based on the deserialization function to obtain the target key-value pairs in the configuration file.

[0130] In this embodiment, when the computer subroutine stored in the computer-readable storage medium is executed by the processor, the following steps can be specifically implemented: after modifying the value in the target key-value pair to the combined value, the modified target key-value pair is serialized based on the serialization function to obtain a new configuration file.

[0131] In this embodiment, when the computer subroutine stored in the computer-readable storage medium is executed by the processor, it can specifically implement the following steps: if the data type of the value in the target key-value pair is a scalar or an array, search for a key-value pair in the storage medium that has the same key value as the target key-value pair; modify the value in the target key-value pair to the value in the found key-value pair.

[0132] In this embodiment, when the computer subroutine stored in the computer-readable storage medium is executed by the processor, the following steps can be specifically implemented: after parsing the configuration file to obtain the target key-value pair in the configuration file, the value in the target key-value pair is saved as a string type; the data type of the value in the target key-value pair is determined based on the saved value.

[0133] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0134] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0135] The above provides a detailed description of a configuration file parsing method, apparatus, device, and medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A configuration file parsing method, characterized by, include: The configuration file is parsed to obtain the target key-value pairs in the configuration file; Determine the data type of the value in the target key-value pair; If the data type of the value is an object type, then the multi-level key-value pairs corresponding to the target key-value pair are determined from the storage medium. Analyze the parent-child relationship of each key-value pair in the multi-level key-value pair, and determine the combined value based on the parent-child relationship; Modify the value in the target key-value pair to the combined value; The step of determining the multi-level key-value pairs corresponding to the target key-value pair from the storage medium includes: determining the multi-level key-value pairs corresponding to the target key-value pair from the storage medium based on the key value in the target key-value pair; wherein the key value of the highest level in the multi-level key-value pairs is the same as the key value in the target key-value pair; The process of analyzing the parent-child relationships of each key-value pair in the multi-level key-value pairs and determining the combined value based on these relationships includes: determining the root node in the multi-level key-value pairs; finding the child nodes of the root node; if the child node has no child nodes, assigning the key-value pair of the child node as an object to the key of the root node; if the child node has child nodes, continuing the parent-child relationship determination until a node with no child nodes is found, and determining the combined value based on the parent-child relationships of each key-value pair; finally, the value of the root node is composed of the key-value values ​​of all child nodes and grandchild nodes or great-grandchild nodes.

2. The configuration file parsing method according to claim 1, wherein, The step of parsing the configuration file to obtain the target key-value pairs in the configuration file includes: The configuration file is parsed using a deserialization function to obtain the target key-value pairs in the configuration file.

3. The configuration file parsing method of claim 1, wherein, After modifying the value in the target key-value pair to the combined value, the method further includes: The modified target key-value pairs are serialized using a serialization function to obtain a new configuration file.

4. The configuration file parsing method of claim 1, wherein, If the data type of the value in the target key-value pair is a scalar or array, it also includes: Search the storage medium for a key-value pair that has the same key value as the target key-value pair. Modify the value in the target key-value pair to the value in the found key-value pair.

5. The configuration file parsing method according to any one of claims 1 to 4, characterized in that, After parsing the configuration file to obtain the target key-value pairs in the configuration file, the process further includes: The value in the target key-value pair is saved as a string. Accordingly, determining the data type of the value in the target key-value pair includes: The data type of the value in the target key-value pair is determined based on the saved value.

6. A configuration file parsing apparatus characterized by comprising: include: The configuration file parsing module is used to parse the configuration file to obtain the target key-value pairs in the configuration file; The data type determination module is used to determine the data type of the value in the target key-value pair. A multi-level key-value pair determination module is used to determine, if the data type of the value is an object type, the multi-level key-value pair corresponding to the target key-value pair from the storage medium; The combined value determination module is used to analyze the parent-child relationship of each key-value pair in the multi-level key-value pair and determine the combined value based on the parent-child relationship; The value modification module is used to modify the value in the target key-value pair to the combined value. The step of determining the multi-level key-value pairs corresponding to the target key-value pair from the storage medium includes: determining the multi-level key-value pairs corresponding to the target key-value pair from the storage medium based on the key value in the target key-value pair; wherein the key value of the highest level in the multi-level key-value pairs is the same as the key value in the target key-value pair. Analyzing the parent-child relationships of each key-value pair in the multi-level key-value pairs and determining the combined value based on these relationships includes: determining the root node in the multi-level key-value pairs; finding the child nodes of the root node; if the child node has no child nodes, assigning the key-value pair of the child node as an object to the key of the root node; if the child node has child nodes, continuing the parent-child relationship judgment until a node with no child nodes is found, and determining the combined value based on the parent-child relationships of each key-value pair; finally, the value of the root node is composed of the key-value values ​​of all child nodes and grandchild nodes or great-grandchild nodes.

7. An electronic device, comprising: Includes memory and processor, wherein: The memory is used to store computer programs; The processor is configured to execute the computer program to implement the configuration file parsing method as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, A computer program product for saving a computer program, wherein the computer program, when executed by a processor, implements the configuration file parsing method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Data processing method and device and storage medium

    CN113391791A