Data conversion method and device, storage medium, and electronic device
Patent Information
- Application Number
- CN202110173002.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-08
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2041-02-08
AI Technical Summary
The prior art maintains the back-end output data format and related conversion methods code of multiple APP versions in the back-end system, resulting in increased system burden and high maintenance costs.
By responding to the client's data display request, the corresponding data conversion template and source data are obtained, the template is parsed to determine the leaf node, the corresponding child nodes are determined in the source data according to the mapping relationship, and the conversion is performed according to the data type, and the target output data is generated to send it to the client.
It reduces business logic changes when the client output data changes, reduces system burden and maintenance costs, and improves the efficiency of data conversion.
Smart Images

Figure CN113779121B_ABST
Abstract
Description
Background Art
[0002] In the prior art, for the backend system that the application client relies on, due to the continuous upgrade of the application version, the content of the source data corresponding to the same function in the client remains unchanged, but the output source data is required to have a different data format from the previous version.
[0003] In order to solve the above problems, in the prior art, a new HTTP (Hyper Text Transfer Protocol) interface may be added, or data conversion logic may be designed for compatibility processing.
[0004] However, if it is impossible to require users to upgrade the application client forcibly, the back-end system must maintain the back-end output data format and related conversion method codes for multiple APP versions for a long time, which increases the system burden.
[0005] Therefore, a new data conversion method needs to be provided.
[0006] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present invention, and therefore may include information that does not constitute prior art known to ordinary technicians in the field. Summary of the invention
[0007] The object of the present invention is to provide a data conversion method, a data conversion device, a storage medium and an electronic device, thereby overcoming the problem of heavy system burden caused by the limitations and defects of the relevant technology at least to a certain extent.
[0008] According to one aspect of the present disclosure, there is provided a data conversion method, comprising:
[0009] In response to a data display request from a client, a data conversion template and source data corresponding to the data display request are obtained, and the data conversion template is parsed to obtain one or more first sub-nodes included in the data conversion template;
[0010] When it is determined that any of the first child nodes is a leaf node, determining a second child node corresponding to the first child node in the source data according to a mapping relationship included in the first child node;
[0011] According to the data type required by the first child node, convert the data format of the node data included in the second child node, and generate target output data according to the node data after the format conversion;
[0012] The target output data is sent to the client, so that the client displays the target output data.
[0013] In an exemplary embodiment of the present disclosure, obtaining a data conversion template corresponding to the data display request includes:
[0014] Generate the data conversion template according to the data type of the target output data displayed by the client and the mapping relationship between the target output data and the source data;
[0015] According to the name of the data conversion template included in the data display request, a data conversion template corresponding to the data display request is determined.
[0016] In an exemplary embodiment of the present disclosure, the data conversion template is parsed to obtain one or more first sub-nodes included in the data conversion template, including:
[0017] Parsing the data conversion template to obtain a data conversion template memory object; wherein the data conversion template memory object is a tree structure;
[0018] Parsing the data conversion template memory object to obtain a root node included in the data conversion template memory object;
[0019] According to the root node, one or more first child nodes included in the data conversion template memory object are obtained.
[0020] In an exemplary embodiment of the present disclosure, before determining the second sub-node corresponding to the first sub-node in the source data, the data conversion method further includes:
[0021] Read the source data, and parse the source data into a source data memory object; wherein the source data memory object is a tree structure;
[0022] Identify the data type of the node data included in one or more second child nodes included in the source data memory object; wherein the data type of the node data included in the second child node is one of a set type, an array type and a basic type;
[0023] It is determined whether the data type required by the first child node and the data type of the data node included in the second child node meet the conversion condition.
[0024] In an exemplary embodiment of the present disclosure, determining whether the data type required by the first child node and the data type of the data node included in the second child node meet the conversion condition includes:
[0025] Recording the data types required by one or more first child nodes included in the data conversion template memory object;
[0026] Determine whether the data type required by the first child node and the data type of the node data included in the second child node can be converted to each other;
[0027] When the data type required by the first sub-node and the data type of the node data included in the second sub-node can be converted to each other, the second sub-node is determined as a sub-node corresponding to the first sub-node.
[0028] In an exemplary embodiment of the present disclosure, determining whether the data type required by the first child node and the data type of the data node included in the second child node meet the conversion condition further includes:
[0029] Determine a first number of array-type child nodes included in a path from the first child node to the root node of the data conversion template memory object;
[0030] Determine a second number of array type nodes included in a path from a second child node corresponding to the first child node to a root node of the source data memory object;
[0031] It is determined whether the first number is the same as the second number, and when it is determined that the first number is the same as the second number, the second sub-node is determined as a sub-node corresponding to the first sub-node.
[0032] In an exemplary embodiment of the present disclosure, converting the data format of the node data included in the second sub-node according to the data type required by the first sub-node includes:
[0033] Determine whether the data type required by the first child node is the same as the data type of the node data included in the second child node;
[0034] When the data type required by the first subnode is the same as the data type of the node data included in the second subnode, taking the node data included in the second subnode as the target output data;
[0035] When the data type required by the first subnode is different from the data type of the node data included in the second subnode, the node data included in the second subnode is converted according to the data type required by the first subnode to obtain target output data.
[0036] According to one aspect of the present disclosure, there is provided a data conversion device, comprising:
[0037] A request response module, used to respond to a data display request from a client, obtain a data conversion template and source data corresponding to the data display request, and parse the data conversion template to obtain one or more first sub-nodes included in the data conversion template;
[0038] a second sub-node determining module, configured to determine, when determining that any of the first sub-nodes is a leaf node, a second sub-node corresponding to the first sub-node in the source data according to a mapping relationship included in the first sub-node;
[0039] A data conversion module, used to convert the data format of the node data included in the second sub-node according to the data type required by the first sub-node, and generate target output data according to the node data after the format conversion;
[0040] The data display module is used to send the target output data to the client so that the client displays the target output data.
[0041] According to one aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the data conversion method described in any one of the above is implemented.
[0042] According to one aspect of the present disclosure, there is provided an electronic device, including:
[0043] Processor; and
[0044] A memory, configured to store executable instructions of the processor;
[0045] The processor is configured to execute any one of the above-mentioned data conversion methods by executing the executable instructions.
[0046] A data conversion method provided by an embodiment of the present disclosure responds to a data display request of a client, obtains a data conversion template and source data corresponding to the data display request; parses the data conversion template to obtain a first child node included in the data conversion template; when determining that the first child node is a leaf node, determines a second child node corresponding to the first child node according to a mapping relationship between a second child node in the source data included in the first child node and the first child node; according to the data type of the first child node included in the data conversion template, converts the output data corresponding to the second child node into the data type of the first child node, and displays it in the client. Since the data conversion template corresponding to the request can be determined according to the data display request of the client, and the format of the source data corresponding to the client display data is converted according to the data conversion template, the business logic changes generated when the output data of the client changes are reduced, the system burden is reduced, and the maintenance cost is reduced. At the same time, since the source data corresponding to the client data display request can be determined according to the mapping relationship included in the leaf node, the efficiency of data conversion is improved, and the data format of the source data is converted based on the data type required by the first child node, the efficiency of data conversion is improved.
[0047] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The accompanying drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present invention, and together with the specification are used to explain the principles of the present invention. Obviously, the accompanying drawings described below are only some embodiments of the present invention, and for those of ordinary skill in the art, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0049] Figure 1 The following schematically shows a flow chart of a data conversion method according to an exemplary embodiment of the present invention.
[0050] Figure 2 A block diagram of a data conversion system according to an exemplary embodiment of the present invention is schematically shown.
[0051] Figure 3 A flow chart of a method for generating a data conversion template according to an exemplary embodiment of the present invention is schematically shown.
[0052] Figure 4 A flowchart of a method for obtaining a sub-node included in a data conversion template according to an exemplary embodiment of the present invention is schematically shown.
[0053] Figure 5A schematic diagram of a data conversion template memory object according to an exemplary embodiment of the present invention is schematically shown.
[0054] Figure 6 A flow chart schematically illustrates a method for data conversion before determining a second sub-node corresponding to a first sub-node according to an exemplary embodiment of the present invention.
[0055] Figure 7 A schematic diagram of a source data memory object according to an exemplary embodiment of the present invention is schematically shown.
[0056] Figure 8 A flowchart of a method for determining whether a data type required by a first child node and a data type of a data node included in a second child node meet a conversion condition according to an exemplary embodiment of the present invention is schematically output.
[0057] Fig. 9 The following schematically shows a flow chart of a data conversion method according to an exemplary embodiment of the present invention.
[0058] Fig.10 A block diagram schematically shows a data conversion device according to an exemplary embodiment of the present invention.
[0059] Fig.11 An electronic device for implementing the above data conversion method according to an exemplary embodiment of the present invention is schematically shown. DETAILED DESCRIPTION
[0060] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present invention will be more comprehensive and complete, and the concept of the example embodiments will be fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present invention. However, those skilled in the art will appreciate that the technical solutions of the present invention may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present invention.
[0061] In addition, the accompanying drawings are only schematic illustrations of the present invention and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0062] Existing business websites usually adopt a front-end and back-end separation architecture. The front-end system provides page rendering functions, and the back-end service provides output data through the HTTP protocol. The output data is usually in JSON (JavaScript Object Notation) format. The source data provided by the back-end service contains the same information as the data that the front-end system needs to display, but has different data structures. Usually, when the back-end service needs to output different output data, different HTTP interfaces must be provided for different output data. The data in the interface is usually obtained from a database or RPC (Remote Procedure Call), and the conversion logic of converting the source data into the data structure required by the front-end system is fixed in the code. When the source data structure or the data structure required by the front-end system changes, the code corresponding to the conversion logic must be modified and re-applied for online, forming a maintenance cost for the back-end service.
[0063] In addition, in the backend services that the application software client (Android and IOS) relies on, since the source data corresponding to the same function of the new version of the application software client is the same as that of the old version of the client, the data output by the backend service may require different data structures or contents. In the prior art, the compatibility of the new and old versions is processed by adding HTTP interfaces or data conversion logic. When it is impossible to force users to upgrade the client version, the backend service must maintain the backend service output data format and related conversion logic code for multiple client versions for a long time, resulting in a heavy burden on the system and increased maintenance costs.
[0064] Based on one or more of the above problems, this exemplary embodiment first provides a data conversion method, which can be run on a server. Of course, those skilled in the art can also run the method of the present invention on other platforms as required, and this exemplary embodiment does not specifically limit this. Figure 1 As shown, the data conversion method may include the following steps:
[0065] Step S110. Respond to the data display request of the client, obtain a data conversion template and source data corresponding to the data display request, and parse the data conversion template to obtain one or more first sub-nodes included in the data conversion template;
[0066] Step S120. When it is determined that any of the first child nodes is a leaf node, a second child node corresponding to the first child node is determined in the source data according to the mapping relationship included in the first child node;
[0067] Step S130. According to the data type required by the first child node, the data format of the node data included in the second child node is converted, and target output data is generated according to the node data after the format conversion;
[0068] Step S140: Send the target output data to the client, so that the client displays the target output data.
[0069] The above-mentioned data conversion method responds to the data display request of the client, obtains the data conversion template and source data corresponding to the data display request; parses the data conversion template to obtain the first child node included in the data conversion template; when determining that the first child node is a leaf node, determines the second child node corresponding to the first child node according to the mapping relationship between the second child node in the source data included in the first child node and the first child node; according to the data type of the first child node included in the data conversion template, converts the output data corresponding to the second child node into the data type of the first child node, and displays it in the client. Since the data conversion template corresponding to the request can be determined according to the data display request of the client, and the format of the source data corresponding to the client display data is converted according to the data conversion template, the business logic changes generated when the output data of the client changes are reduced, the system burden is reduced and the maintenance cost is reduced; at the same time, since the source data corresponding to the client data display request can be determined according to the mapping relationship included in the leaf node, the efficiency of data conversion is improved, and the data format of the source data is converted based on the data type required by the first child node, the efficiency of data conversion is improved.
[0070] Hereinafter, each step involved in the data conversion method according to the exemplary embodiment of the present disclosure is explained and illustrated in detail.
[0071] First, the application scenarios and invention objectives of the exemplary embodiments of the present disclosure are explained and illustrated.
[0072] Specifically, the example embodiments of the present disclosure can be used in device terminals with separated front-end and back-end, mainly through customizing data conversion templates. When the structure of the data that the front-end system needs to display is different from the data structure of the source data, or when the structure of the source data provided by the back-end service changes, it can reduce business logic changes and reduce the maintenance cost of the back-end service.
[0073] The example embodiment of the present disclosure is based on a customized data conversion template. After obtaining the source data corresponding to the data to be displayed on the front end, a mapping relationship between the source data and the output data is established through the customized data conversion template. Through the mapping relationship and the data format of the data to be displayed in the data conversion template, the source data is converted into the corresponding target output data and displayed on the client. The source data can be configured with multiple data conversion templates, and each data conversion template has corresponding target output data. When the format of the data to be displayed on the front end changes or the data format of the source data changes, by calling different data conversion templates, the business logic changes when the changes occur are reduced, and the maintenance cost is reduced.
[0074] Next, the data conversion system involved in the exemplary embodiment of the present disclosure is explained and illustrated. Figure 2 As shown, the data conversion system may include a source data processor 210, a conversion template processor 220, a data converter 230, and a data output processor 240. The source data processor 210 is used to read and parse the source data, obtain the source data memory object, and store the source data memory object in the system memory; the conversion template processor 220 is connected to the source data processor 210 through a network, and is used to read and parse the data conversion template, generate a data conversion template memory object including the structure of the target output data and the mapping relationship with the source data, and store the data conversion template memory object in the system memory; the data converter 230 is connected to the source data processor 210 and the conversion template processor 220 through a network, and is used to read the source data memory object and the data conversion template memory object, convert the source data into the target output data memory object according to the data conversion method defined by the data converter, and store the target output data memory object in the system memory; the data output processor 240 is connected to the data converter 230 through a network, and is used to read the target output data memory object, and output the target output data included in the target output memory object.
[0075] The following will be combined Figure 2 Steps S110 to S130 are explained and described.
[0076] In step S110, in response to the data display request of the client, a data conversion template and source data corresponding to the data display request are obtained, and the data conversion template is parsed to obtain one or more first sub-nodes included in the data conversion template.
[0077] The data display request is initiated by the client, and the data display request includes the target output data to be displayed, the data type of the target output data, and the name of the data conversion template corresponding to the data type of the target output data. When the server responds to the client's data display request, it needs to determine the data conversion template corresponding to the data display request according to the name of the data conversion template included in the data display request.
[0078] Before obtaining the data conversion template, the server needs to generate a data conversion template based on the content of the target output data that the client needs to display and the data structure of the target output data. For details, refer to Figure 3 As shown, obtaining a data conversion template corresponding to the data display request may include:
[0079] Step S310. Generate the data conversion template according to the data type of the target output data displayed by the client and the mapping relationship between the target output data and the source data;
[0080] Step S320: Determine a data conversion template corresponding to the data display request according to the name of the data conversion template included in the data display request.
[0081] Step S310 and step S320 are explained and illustrated below. Specifically, the data conversion template is a tree structure, which is used to describe the structure of the target output data. Each child node in the tree structure at least includes a node name (name) and a data type (type). When the child node in the tree structure is a leaf node, that is, the child node does not have a next-level child node, and the leaf node includes a node name, a node type, and a mapping relationship (value) between the target output data and the source data, wherein the node name can be a child node name or a field name of the target output data, the node type is the data type of the target output data, and the mapping relationship is a mapping relationship between the first child node in the data conversion template and the second child node included in the source data, and the second child node of the source data included in the mapping relationship is the child node corresponding to the target output data. Since the path from the root node of the source data to a certain leaf node is unique, the mapping relationship can be represented in the form of a path.
[0082] For example, the root node of the source data may include three child nodes: source_1, source_2, and source_3; for the child node source_1, the data type is a collection type, which may include: source_1_1, the data type is a collection type, which may include the child node source_1_1_1, the data type is an array type, and the node data includes "aaa", "bbb", and "ccc"; source_1_2, the data type is a basic type, and the node data is 123; for the child node source_2, it may include the child node source_2_1, the data type is a collection type, and the node data includes: "skuId": 8934378, "venderId": 1; for the child node source_3, the data type is an array type, which may include the child node Point source_3_1, the data type is a collection type, and the data nodes include "promotionId": "aaa", "promotionType": 6 and "promotionId": "bbb", "promotionType": 10; the child node source_3_2, the data type is an array type, and may include the child node source_3_2_1, the data type is a collection type, and the node data may include: "shopId": 111, "shopName": "JD1", "shopId": 112, "shopName": "JD2", "shopId": 2221, "shopName": "JX1" and "shopId": 112, "shopName": "JX2".
[0083] When it is necessary to identify the source_2_2 child node, "." can be used as the path separator from the root node to the node, that is, source_2.source_2_2 can be used to identify the source_2_2 child node, where other symbols can also be used as path separators, which are not specifically limited in this example embodiment. In addition, when the path from the leaf node to the root node contains child nodes whose node type is an array type, other special identifiers need to be added. For example, "#." can be added after the child node whose node type is an array type as an identifier. For example, source_3_2_1 can be identified by source_3.source_3_2.#.source_3_2_1, where other special characters can also be used to identify child nodes whose node type is an array type, which are not specifically limited in this example embodiment.
[0084] The name (name) of the subnode included in the data conversion template is the field name of the target output data, the type (type) is the data type of the data node included in the second subnode included in the data conversion template, and the value value is the mapping relationship between the source data and the target display data, and the specific form is the path of the source data subnode.
[0085] After the data conversion template is generated, the server determines the data conversion template corresponding to the data display request according to the name of the data conversion template included in the data display request.
[0086] In this example embodiment, reference Figure 4 As shown, parsing the data conversion template to obtain one or more first sub-nodes included in the data conversion template may include steps S410 to S430:
[0087] Step S410: Parse the data conversion template to obtain a data conversion template memory object; wherein the data conversion template memory object is a tree structure;
[0088] Step S420: Parse the data conversion template memory object to obtain the root node included in the data conversion template memory object;
[0089] Step S430: According to the root node, obtain one or more first child nodes included in the data conversion template memory object.
[0090] The following explains and illustrates steps S410 to S430. Specifically, first, the conversion template processor 220 reads the data conversion template and parses the data conversion template to obtain a data conversion template memory object including the data type of the target output data and the mapping relationship with the source data, wherein the data conversion template memory object is a tree structure; then, the conversion template processor 220 parses the data conversion template memory object to obtain the root node included in the memory object; finally, traverse the root node to obtain one or more first child nodes included in the data conversion template memory object.
[0091] For example, when the client needs to display the target output data, that is, the node names of the data conversion template are: target_1, target_2 and target_3, among which, the child node included in target_1 can be: target_1_1, the data type to be displayed is an array type, and the corresponding source data node is source_1.source_1_1.source_1_1_1; the data type to be displayed by target_2 is a collection type, and the corresponding source data nodes are: source_2.source_2_1.skuId; the child nodes included in target_3 can be: the collection target_3_1, target_3_2, and the collection target_3_1, target_3_2; the data type to be displayed by target_3_1 is a collection type, and the corresponding source data node is source_3.#.source_3_1.promotionId; the data type to be displayed by target_3_2 is an array type, and the corresponding source data node is source_3.#.source_3_2.#.source_3_2_1.shopId. Parsing the data conversion template can obtain Figure 5 The data transformation template memory object shown.
[0092] In step S120, when it is determined that any of the first sub-nodes is a leaf node, a second sub-node corresponding to the first sub-node is determined in the source data according to a mapping relationship included in the first sub-node.
[0093] Among them, a leaf node is a child node that does not have a next-level child node. Specifically, the data converter 230 reads the data conversion template memory object. When the child node included in the data conversion template memory object is a leaf node, the second child node included in the source data corresponding to the leaf node is determined based on the mapping relationship between the target output data included in the leaf node and the source data.
[0094] In this example embodiment, reference Figure 6 As shown, before determining the second sub-node corresponding to the first sub-node in the source data, the data conversion method further includes steps S610 to S630:
[0095] Step S610: Read the source data and parse the source data into a source data memory object; wherein the source data memory object is a tree structure;
[0096] Step S620. Identify the data type of the node data included in one or more second child nodes included in the source data memory object; wherein the data type of the node data included in the second child node is one of a set type, an array type and a basic type;
[0097] Step S630: Determine whether the data type required by the first child node and the data type of the data node included in the second child node meet the conversion conditions.
[0098] The following will explain and illustrate steps S610 to S630. Specifically, first, the data converter 230 reads and parses the source data corresponding to the target output data, and parses it into a source data memory object, wherein the source data processor 220 supports reading source data in JSON or YAML (YAML Ain't a Markup Language, YAML is not a markup language) format, and the source data memory object is a tree structure. The source data memory object obtained by the data converter after parsing the source data recorded in steps S310 and S320 can be referred to. Figure 7 As shown; Then, when the source data is parsed into a tree structure, since JSON or YAML contains three types of data structures, namely, key-value mapping type (map type, collection type), array type (array type) and base type (base type, a general term for string and numeric types), it is necessary to identify the data type of the node data included in one or more second child nodes included in the source data, and the identification may include identifying the node name of the second child node and the data type of the second node. In addition, since the array type data contains multiple output data, when parsed into a tree structure, the output data in the array can be merged into a data child node, and the root node may not contain any specific data, but only serve as a connection point for each data node; Finally, after identifying the data type of the node data included in the child node of the source data, it is also necessary to determine whether the data type of the node data included in the second child node of the source data and the node type required by the first child node included in the data conversion template can be converted to each other.
[0099] By identifying the data type of the node data included in the second child node of the source data, and judging whether the data type of the node data included in the second child node and the data type required by the first child node can be converted to each other before data conversion, the error rate of data conversion is reduced and the efficiency of data conversion is improved.
[0100] For further reference, Figure 8As shown, judging whether the data type required by the first sub-node and the data type of the data node included in the second sub-node meet the conversion condition may include steps S810 to S830:
[0101] Step S810. Record the data type required by one or more first child nodes included in the data conversion template memory object;
[0102] Step S820: Determine whether the data type required by the first child node and the data type of the node data included in the second child node can be converted to each other;
[0103] Step S830: When the data type required by the first sub-node and the data type of the node data included in the second sub-node can be converted to each other, the second sub-node is determined as the sub-node corresponding to the first sub-node.
[0104] Steps S810 to S830 are explained and illustrated below. The data type required by the first child node may also be any one of a map type, an array type, and a base type. The data type required by the first child node included in the data conversion template memory object is recorded, and it is determined whether the data type required by the first child node and the data type of the node data included in the second child node can be converted to each other. For example, when the data type required by the first child node is a map type and the data type of the node data included in the second child node is an array type, since the map type data cannot be converted into array type data, the first child node and the second child node cannot be converted to each other. When the data type required by the first child node and the data type of the node data included in the second child node can be converted to each other, the second child node of the source data is determined as the child node corresponding to the first child node included in the data conversion template.
[0105] Furthermore, determining whether the data type required by the first child node and the data type of the data node included in the second child node meet the conversion condition further includes:
[0106] Determine a first number of array-type child nodes included in a path from the first child node to the root node of the data conversion template memory object;
[0107] Determine a second number of array type nodes included in a path from a second child node corresponding to the first child node to a root node of the source data memory object;
[0108] It is determined whether the first number is the same as the second number, and when it is determined that the first number is the same as the second number, the second sub-node is determined as a sub-node corresponding to the first sub-node.
[0109] Specifically, since the path from the child node to the root node is unique, it is possible to determine whether a conversion can occur between the two parties by determining whether the number of array-type child nodes included in the path from the leaf node to the root node in the data conversion template memory object is the same as the number of array-type child nodes included in the path from the leaf node to the root node in the source data memory object. When the first number of array-type child nodes included in the path from the first child node to the root node in the data conversion template memory object is the same as the second number of array-type child nodes included in the path from the second child node to the root node in the source data memory template, the second child node can be determined as the child node corresponding to the first child node.
[0110] When it is determined that the first sub-node and the second sub-node meet the conditions for mutual conversion, the sub-node of the data conversion template memory object can be replaced with the sub-node of the source data memory object through the data converter 230.
[0111] In step S130, the data format of the node data included in the second sub-node is converted according to the data type required by the first sub-node, and target output data is generated according to the node data after the format conversion.
[0112] In this exemplary embodiment, converting the data format of the node data included in the second sub-node according to the data type required by the first sub-node includes:
[0113] Determine whether the data type required by the first child node is the same as the data type of the node data included in the second child node;
[0114] When the data type required by the first subnode is the same as the data type of the node data included in the second subnode, taking the node data included in the second subnode as the target output data;
[0115] When the data type required by the first subnode is different from the data type of the node data included in the second subnode, the node data included in the second subnode is converted according to the data type required by the first subnode to obtain target output data.
[0116] Specifically, when the data converter 230 converts the data nodes in the data conversion template, it first determines whether the data type required by the first child node is the same as the data type of the node data included in the second child node. When the data type required by the first child node is the same as the data type of the node data included in the second child node, there is no need to convert the format of the source data. It is only necessary to output the target output data required to be displayed by the client through the data output processor 240 based on the mapping relationship between the target output data and the source data included in the data conversion template; when the data type required by the first child node is different from the data type of the node data included in the second child node, it is first necessary to convert the acquired source data into data consistent with the data type of the target output data required to be displayed by the client, and display the target output data on the client through the data output processor 240, wherein the format of the target output data output by the data output processor 240 can be JSON type or YAML type, which is not specially limited in this example embodiment. According to the source data recorded in steps S310 and S320 and the data conversion template recorded in steps S410-S430, the target output data can be obtained. For example, according to the mapping relationship included in the sub-node target_1_1 in the data conversion template, the target output data corresponding to the sub-node can be obtained as "aaa", "bbb", and "ccc"; the target output data corresponding to the sub-node target_2 is 8934378, and the target output data corresponding to the sub-node sets target_3_1 and target_3_2 included in the sub-node target_3 are: "aaaaaaaaaaaa" and 111, 112; the target output data corresponding to the other set target_3_1 and target_3_2 are: "bbbbbbbbbb" and 2221, 2222.
[0117] In step S140, the target output data is sent to the client, so that the client displays the target output data.
[0118] After obtaining the target output data through the data converter 230, the data converter saves the target output data in the system memory to obtain the target output data memory object. The data output processor 240 reads the target output data memory object saved in the system memory and outputs the target output data included in the target memory object to the client, so that the client displays the target data.
[0119] The data conversion method and data conversion system provided by the exemplary embodiments of the present disclosure have at least the following advantages: a data conversion template is generated according to the target output data that the client needs to display and the mapping relationship between the target output data and the source data, and the source data is replaced according to the data conversion template, thereby improving the front-end and back-end data conversion efficiency and reducing the system burden.
[0120] The following, combined Fig. 9 The data conversion method of the exemplary embodiment of the present disclosure is further explained and illustrated. The data conversion method may include the following steps:
[0121] Step S910. Respond to the data display request of the client and obtain a data conversion template corresponding to the data display request;
[0122] Step S920. The conversion template processor reads and parses the data conversion template memory object to obtain the child nodes included in the data conversion template;
[0123] Step S930. Traverse the sub-nodes included in the data conversion template;
[0124] Step S940. Record the node name and node type of the child node;
[0125] Step S950. Determine whether the child node is a leaf node;
[0126] Step S960. When the child node is a leaf node, determine the child node of the source data corresponding to the leaf node according to the mapping relationship between the leaf node and the source data; when the child node is not a leaf node, return to step S930;
[0127] Step S970: Parse the sub-nodes of the source data and replace the leaf nodes of the data conversion template with the sub-nodes of the source data;
[0128] Step S980. Convert all leaf nodes in the data conversion template into corresponding child nodes of the source data to obtain the target output data memory object;
[0129] Step S990. The data output processor reads the target output data memory object and outputs the target output data.
[0130] The exemplary embodiment of the present disclosure also provides a data conversion device, referring to Fig.10 As shown, the data conversion device may include: a request response module 1010, a second sub-node determination module 1020, a data conversion module 1030 and a data display module 1040. Among them:
[0131] The request response module 1010 is used to respond to the data display request of the client, obtain the data conversion template and source data corresponding to the data display request, and parse the data conversion template to obtain one or more first sub-nodes included in the data conversion template;
[0132] A second subnode determination module 1020, configured to determine, when determining that any of the first subnodes is a leaf node, a second subnode corresponding to the first subnode in the source data according to a mapping relationship included in the first subnode;
[0133] The data conversion module 1030 is used to convert the data format of the node data included in the second child node according to the data type required by the first child node, and generate target output data according to the node data after the format conversion;
[0134] The data display module 1040 is used to send the target output data to the client so that the client displays the target output data.
[0135] In an exemplary embodiment of the present disclosure, obtaining a data conversion template corresponding to the data display request includes:
[0136] generating the data conversion template according to the data type of the target output data displayed by the client and the mapping relationship between the target output data and the source data;
[0137] According to the name of the data conversion template included in the data display request, a data conversion template corresponding to the data display request is determined.
[0138] In an exemplary embodiment of the present disclosure, the data conversion template is parsed to obtain one or more first sub-nodes included in the data conversion template, including:
[0139] Parsing the data conversion template to obtain a data conversion template memory object; wherein the data conversion template memory object is a tree structure;
[0140] Parsing the data conversion template memory object to obtain a root node included in the data conversion template memory object;
[0141] According to the root node, one or more first child nodes included in the data conversion template memory object are obtained.
[0142] In an exemplary embodiment of the present disclosure, before determining the second sub-node corresponding to the first sub-node in the source data, the data conversion method further includes:
[0143] Read the source data, and parse the source data into a source data memory object; wherein the source data memory object is a tree structure;
[0144] Identify the data type of the node data included in one or more second child nodes included in the source data memory object; wherein the data type of the node data included in the second child node is one of a set type, an array type and a basic type;
[0145] It is determined whether the data type required by the first child node and the data type of the data node included in the second child node meet the conversion condition.
[0146] In an exemplary embodiment of the present disclosure, determining whether the data type required by the first child node and the data type of the data node included in the second child node meet the conversion condition includes:
[0147] Recording the data types required by one or more first child nodes included in the data conversion template memory object;
[0148] Determine whether the data type required by the first child node and the data type of the node data included in the second child node can be converted to each other;
[0149] When the data type required by the first sub-node and the data type of the node data included in the second sub-node can be converted to each other, the second sub-node is determined as a sub-node corresponding to the first sub-node.
[0150] In an exemplary embodiment of the present disclosure, determining whether the data type required by the first child node and the data type of the data node included in the second child node meet the conversion condition further includes:
[0151] Determine a first number of array-type child nodes included in a path from the first child node to the root node of the data conversion template memory object;
[0152] Determine a second number of array type nodes included in a path from a second child node corresponding to the first child node to a root node of the source data memory object;
[0153] It is determined whether the first number is the same as the second number, and when it is determined that the first number is the same as the second number, the second sub-node is determined as a sub-node corresponding to the first sub-node.
[0154] In an exemplary embodiment of the present disclosure, converting the data format of the node data included in the second sub-node according to the data type required by the first sub-node includes:
[0155] Determine whether the data type required by the first child node is the same as the data type of the node data included in the second child node;
[0156] When the data type required by the first subnode is the same as the data type of the node data included in the second subnode, taking the node data included in the second subnode as the target output data;
[0157] When the data type required by the first subnode is different from the data type of the node data included in the second subnode, the node data included in the second subnode is converted according to the data type required by the first subnode to obtain target output data.
[0158] The specific details of each module in the above data conversion device have been described in detail in the corresponding data conversion method, so they will not be repeated here.
[0159] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to an embodiment of the present invention, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0160] In addition, although the steps of the method of the present invention are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0161] In an exemplary embodiment of the present invention, an electronic device capable of implementing the above data conversion method is also provided.
[0162] It will be appreciated by those skilled in the art that various aspects of the present invention may be implemented as a system, method or program product. Therefore, various aspects of the present invention may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as a "circuit", "module" or "system".
[0163] Reference below Fig.11 The electronic device 1100 according to this embodiment of the present invention is described. Fig.11The electronic device 1100 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0164] like Fig.11 As shown, the electronic device is in the form of a general computing device. The components of the electronic device may include, but are not limited to: the at least one processing unit 1110, the at least one storage unit 1120, a bus 1130 connecting different system components (including the storage unit 1120 and the processing unit 1110), and a display unit 1140.
[0165] The storage unit stores program codes, which can be executed by the processing unit 1110, so that the processing unit 1110 performs the steps according to various exemplary embodiments of the present invention described in the above “Exemplary Method” section of this specification. For example, the processing unit 1110 can perform the following steps: Figure 1 The step S110 shown in the figure: respond to the data display request of the client, obtain the data conversion template and source data corresponding to the data display request, and parse the data conversion template to obtain one or more first child nodes included in the data conversion template; step S120: when it is determined that any of the first child nodes is a leaf node, determine the second child node corresponding to the first child node in the source data according to the mapping relationship included in the first child node; step S130: according to the data type required by the first child node, convert the data format of the node data included in the second child node, and generate target output data according to the node data after the format conversion; step S140: send the target output data to the client, so that the client displays the target output data.
[0166] The storage unit 1120 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 11201 and / or a cache storage unit 11202 , and may further include a read-only storage unit (ROM) 11203 .
[0167] The storage unit 1120 may also include a program / utility 11204 having a set (at least one) of program modules 11205, such program modules 11205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0168] Bus 1130 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0169] The electronic device 1100 may also communicate with one or more external devices 1200 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 1100, and / or communicate with any device that enables the electronic device 1100 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 1150. Furthermore, the electronic device 1100 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 1160. As shown, the network adapter 1160 communicates with other modules of the electronic device 1100 via a bus 1130. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1100, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0170] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present invention.
[0171] In an exemplary embodiment of the present invention, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of this specification is stored. In some possible implementations, various aspects of the present invention can also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to perform the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of this specification.
[0172] The program product for implementing the above method according to an embodiment of the present invention may adopt a portable compact disk read-only memory (CD-ROM) and include program code, and may be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto, and in this document, a readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, apparatus, or device.
[0173] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0174] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0175] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0176] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0177] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0178] Other embodiments of the invention will readily occur to those skilled in the art after considering the specification and practicing the invention invented herein. This application is intended to cover any variations, uses or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art that are not invented by the present invention. The specification and examples are to be considered exemplary only, and the true scope and spirit of the invention are indicated by the claims.
Claims
1. A data conversion method, characterized in that: include: Generate a data conversion template according to the data type of the target output data displayed by the client and the mapping relationship between the target output data and the source data; determine the data conversion template corresponding to the data display request according to the name of the data conversion template included in the data display request; parse the data conversion template to obtain a data conversion template memory object; wherein the data conversion template memory object is a tree structure; parse the data conversion template memory object to obtain a root node included in the data conversion template memory object; obtain one or more first child nodes included in the data conversion template memory object according to the root node; When it is determined that any of the first child nodes is a leaf node, determining a second child node corresponding to the first child node in the source data according to a mapping relationship included in the first child node; According to the data type required by the first child node, convert the data format of the node data included in the second child node, and generate target output data according to the node data after the format conversion; The target output data is sent to the client, so that the client displays the target output data.
2. The data conversion method according to claim 1, characterized in that: Before determining the second subnode corresponding to the first subnode in the source data, the data conversion method further includes: Read the source data, and parse the source data into a source data memory object; wherein the source data memory object is a tree structure; Identify the data type of the node data included in one or more second child nodes included in the source data memory object; wherein the data type of the node data included in the second child node is one of a set type, an array type and a basic type; It is determined whether the data type required by the first child node and the data type of the data node included in the second child node meet the conversion condition.
3. The data conversion method according to claim 2, characterized in that: Determining whether the data type required by the first child node and the data type of the data node included in the second child node meet the conversion condition includes: Recording the data types required by one or more first child nodes included in the data conversion template memory object; Determine whether the data type required by the first child node and the data type of the node data included in the second child node can be converted to each other; When the data type required by the first sub-node and the data type of the node data included in the second sub-node can be converted to each other, the second sub-node is determined as a sub-node corresponding to the first sub-node.
4. The data conversion method according to claim 3, characterized in that: Determining whether the data type required by the first child node and the data type of the data node included in the second child node meet the conversion condition further includes: Determine a first number of array-type child nodes included in a path from the first child node to the root node of the data conversion template memory object; Determine a second number of array type nodes included in a path from a second child node corresponding to the first child node to a root node of the source data memory object; It is determined whether the first number is the same as the second number, and when it is determined that the first number is the same as the second number, the second sub-node is determined as a sub-node corresponding to the first sub-node.
5. The data conversion method according to claim 4, characterized in that: According to the data type required by the first child node, converting the data format of the node data included in the second child node includes: Determine whether the data type required by the first child node is the same as the data type of the node data included in the second child node; When the data type required by the first subnode is the same as the data type of the node data included in the second subnode, taking the node data included in the second subnode as the target output data; When the data type required by the first subnode is different from the data type of the node data included in the second subnode, the node data included in the second subnode is converted according to the data type required by the first subnode to obtain target output data.
6. A data conversion device, characterized in that: include: A request response module, used to generate a data conversion template according to the data type of the target output data displayed by the client and the mapping relationship between the target output data and the source data; determine the data conversion template corresponding to the data display request according to the name of the data conversion template included in the data display request; parse the data conversion template to obtain a data conversion template memory object; wherein the data conversion template memory object is a tree structure; parse the data conversion template memory object to obtain a root node included in the data conversion template memory object; and obtain one or more first child nodes included in the data conversion template memory object according to the root node; a second sub-node determining module, configured to determine, when determining that any of the first sub-nodes is a leaf node, a second sub-node corresponding to the first sub-node in the source data according to a mapping relationship included in the first sub-node; A data conversion module, used to convert the data format of the node data included in the second sub-node according to the data type required by the first sub-node, and generate target output data according to the node data after the format conversion; The data display module is used to send the target output data to the client so that the client displays the target output data.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data conversion method according to any one of claims 1 to 5 is implemented.
8. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; Wherein, the processor is configured to execute the data conversion method described in any one of claims 1-5 by executing the executable instructions.
Citation Information
Patent Citations
Techniques related to binary encoding of hierarchical data objects to support efficient path navigation of the hierarchical data objects
CN107924410A
Data processing method and device
CN111767271A