Method and device for data format conversion

文档序号:1296855 发布日期:2020-08-07 浏览:18次 中文

阅读说明:本技术 一种进行数据格式转换的方法及装置 (Method and device for data format conversion ) 是由 李培 张思文 刘晓钟 苗辉 于 2019-01-31 设计创作,主要内容包括:本发明公开了一种进行数据格式转换的方法及装置,此方法包括:构建至少一个字典,所述字典包括映射对和/或配置项,所述映射对包括显示名称和代码名称;所述配置项包括当前表格或者其它表格中一行的信息对应的JSON数据中与此行对应的元素的信息;构建二维表格;设置所述二维表格中每列的列头的映射对,设置所述二维表格的至少一列与至少一字典绑定,与字典绑定的列中的单元格的内容包括至少一所述显示名称;根据所述二维表格构建JSON数据。本发明典型适用于非技术人员构建JSON数据。(The invention discloses a method and a device for converting data formats, wherein the method comprises the following steps: constructing at least one dictionary, wherein the dictionary comprises mapping pairs and/or configuration items, and the mapping pairs comprise display names and code names; the configuration items comprise information of elements corresponding to a row in JSON data corresponding to information of the row in a current table or other tables; constructing a two-dimensional table; setting a mapping pair of column headers of each column in the two-dimensional table, setting at least one column of the two-dimensional table to be bound with at least one dictionary, wherein the content of cells in the column bound with the dictionary comprises at least one display name; and constructing JSON data according to the two-dimensional table. The invention is typically applicable to non-technical personnel constructing JSON data.)

1. A method for performing data format conversion, comprising:

constructing at least one dictionary, wherein the dictionary comprises mapping pairs and/or configuration items, and the mapping pairs comprise display names and code names; the configuration items comprise information of elements corresponding to a row in JSON data corresponding to information of the row in a current table or other tables;

constructing a two-dimensional table; setting a mapping pair of column headers of each column in the two-dimensional table, setting at least one column of the two-dimensional table to be bound with at least one dictionary, wherein the content of cells in the column bound with the dictionary comprises at least one display name;

constructing JSON data according to the two-dimensional table, wherein the constructing JSON data according to the two-dimensional table comprises the following steps: and converting the display name contained in the two-dimensional table into the code name according to the mapping pair, and setting the code name in the JSON data.

2. The method for data format conversion according to claim 1,

the step of constructing JSON data according to the two-dimensional table comprises the following steps: converting the information of each row of the two-dimensional table into one element in the JSON data respectively;

wherein converting information of a row of the two-dimensional table into one element of the JSON data comprises:

taking the specific value of the line head of the line as the value of the key field of the element corresponding to the line in the JSON data;

converting information of each column except a row header in the row into a common field in an element corresponding to the row in the JSON data, taking a code name corresponding to the information of the column header in a mapping pair of the column header in each column as a code name of the common field, constructing a specific value of the common field according to the content of each column of unit cells, converting a display name in the content of the column of unit cells into a code name as a specific value of the common field according to the mapping pair in the dictionary bound by the column for the column bound with the dictionary, and taking the content of the column of unit cells as the specific value of the common field for the column not bound with the dictionary.

3. The method for data format conversion according to claim 1,

the constructing of the two-dimensional table comprises:

determining an operation type of each column of the two-dimensional table; setting a dictionary bound with a column when the operation type of the column of the two-dimensional table is single selection; when the operation type of the column is single filling or multi filling, determining the data type of the column; setting a dictionary bound with the column when the operation type of the column is mapping and the data type is a non-object type; setting a dictionary which is bound with the column and comprises configuration items when the operation type of the column is mapping and the data type is an object type;

and aiming at each row of the two-dimensional table, setting the content of the cell corresponding to the row and the column according to the operation type of each column.

4. The method for data format conversion according to claim 3,

setting the content of the cell corresponding to the row and the column according to the operation type of each column comprises the following steps:

when the operation type of the column is single selection, selecting a mapping pair from the dictionary bound with the column, and taking the display name in the mapping pair as the content of the cell;

when the column operation type is multi-selection, selecting more than one mapping pair from the dictionary bound with the column, and taking the display name in the mapping pair as the content of the cell;

when the operation type of the column is mapping and the data type is non-object type, selecting more than one mapping pair from a dictionary bound with the column, taking the display name in the mapping pair as a key, and taking the specific value of each item input by a received user as the key value of the corresponding key;

when the operation type of the column is single filling, receiving information filled by a user;

when the operation type of the column is multi-filling, more than one item of information filled by the user is received.

5. The method for data format conversion according to claim 3,

the steps after the two-dimensional table is built and before the JSON data is built according to the two-dimensional table further comprise: adding a new column in the two-dimensional table, wherein the operation type of the column is mapping and the data type is object type, and setting a dictionary which is bound with the column and comprises configuration items;

the setting the content of the cell corresponding to the row and the column according to the operation type of each column comprises: setting the identification of the configuration item in the cell;

the constructing JSON data according to the two-dimensional table comprises the following steps: and setting elements, corresponding to the configuration items in the dictionary comprising the configuration items, of the configuration items contained in the two-dimensional table into the JSON data.

6. An apparatus for performing data format conversion, comprising:

the dictionary construction module is used for constructing at least one dictionary, the dictionary comprises mapping pairs and/or configuration items, and the mapping pairs comprise display names and code names; the configuration items comprise information of elements corresponding to a row in JSON data corresponding to information of the row in a current table or other tables;

the table building module is used for building a two-dimensional table; setting a mapping pair of column headers of each column in the two-dimensional table, setting at least one column of the two-dimensional table to be bound with at least one dictionary, wherein the content of cells in the column bound with the dictionary comprises at least one display name;

the data construction module is used for constructing JSON data according to the two-dimensional table, wherein the construction of the JSON data according to the two-dimensional table comprises the following steps: and converting the display name contained in the two-dimensional table into the code name according to the mapping pair, and setting the code name in the JSON data.

7. The apparatus for data format conversion according to claim 6,

the data construction module comprises an element construction unit, and is used for respectively converting the information of each row of the two-dimensional table into one element in the JSON data; specifically, the following method is used to convert the information of one row of the two-dimensional table into one element in the JSON data:

taking the specific value of the line head of the line as the value of the key field of the element corresponding to the line in the JSON data;

converting information of each column except a row header in the row into a common field in an element corresponding to the row in the JSON data, taking a code name corresponding to the information of the column header in a mapping pair of the column header in each column as a code name of the common field, constructing a specific value of the common field according to the content of each column of unit cells, converting a display name in the content of the column of unit cells into a code name as a specific value of the common field according to the mapping pair in the dictionary bound by the column for the column bound with the dictionary, and taking the content of the column of unit cells as the specific value of the common field for the column not bound with the dictionary.

8. The apparatus for data format conversion according to claim 6,

the table building module comprises a type setting unit and a content setting module;

the type setting unit is used for determining the operation type of each column of the two-dimensional table; setting a dictionary bound with a column when the operation type of the column of the two-dimensional table is single selection; when the operation type of the column is single filling or multi filling, determining the data type of the column; setting a dictionary bound with the column when the operation type of the column is mapping and the data type is a non-object type; setting a dictionary which is bound with the column and comprises configuration items when the operation type of the column is mapping and the data type is an object type;

and the content setting module is used for setting the content of the cell corresponding to each row and column according to the operation type of each column aiming at each row of the two-dimensional table.

9. The apparatus for data format conversion according to claim 8,

the content setting module is further configured to set the content of the cell corresponding to the row and the column according to the operation type of each column by using the following method:

when the operation type of the column is single selection, selecting a mapping pair from the dictionary bound with the column, and taking the display name in the mapping pair as the content of the cell;

when the column operation type is multi-selection, selecting more than one mapping pair from the dictionary bound with the column, and taking the display name in the mapping pair as the content of the cell;

when the operation type of the column is mapping and the data type is non-object type, selecting more than one mapping pair from a dictionary bound with the column, taking the display name in the mapping pair as a key, and taking the specific value of each item input by a received user as the key value of the corresponding key;

when the operation type of the column is single filling, receiving information filled by a user;

when the operation type of the column is multi-filling, more than one item of information filled by the user is received.

10. The apparatus for data format conversion according to claim 8,

the table correction module is used for adding a new column in the two-dimensional table, wherein the operation type of the column is mapping and the data type is object type, and a dictionary which is bound with the column and comprises configuration items is set; the dictionary comprising the configuration items comprises identifications of the configuration items, and the configuration items comprise information of elements corresponding to a row in JSON data corresponding to information of the row in a current table or other tables;

the content setting module is also used for setting the identification of the configuration item in the cell;

the data construction module is further configured to set elements, corresponding to the configuration items included in the two-dimensional table, in the dictionary including the configuration items in the JSON data.

Technical Field

The present invention relates to the field of internet technologies, and in particular, to a method and an apparatus for data format conversion.

Background

JS Object Notation (JSON) is a lightweight data exchange format that stores and represents data in a text format completely independent of programming languages, based on a subset of ECMAScript (JS specification set by the european computer association). The simple and clear hierarchical structure enables JSON to become an ideal data exchange language, is easy for human reading and writing, and is also easy for machine analysis and generation.

The existing JSON data generation is based on data types such as numbers, character strings, arrays, objects and the like built in a programming language. Therefore, a specific programming language needs to be learned to construct a desired object, and the object is further serialized into JSON data. The learning cost of this method is very high, and it needs a certain programming knowledge for non-technical personnel to implement, so how to make it easy for personnel without advanced programming knowledge to implement data format conversion is a technical problem to be solved.

Disclosure of Invention

In order to solve the above technical problem, the present invention provides a method and an apparatus for data format conversion.

The method for converting the data format comprises the following steps:

constructing at least one dictionary, wherein the dictionary comprises mapping pairs and/or configuration items, and the mapping pairs comprise display names and code names; the configuration items comprise information of elements corresponding to a row in JSON data corresponding to information of the row in a current table or other tables;

constructing a two-dimensional table; setting a mapping pair of column headers of each column in the two-dimensional table, setting at least one column of the two-dimensional table to be bound with at least one dictionary, wherein the content of cells in the column bound with the dictionary comprises at least one display name;

constructing JSON data according to the two-dimensional table, wherein the constructing JSON data according to the two-dimensional table comprises the following steps: and converting the display name contained in the two-dimensional table into the code name according to the mapping pair, and setting the code name in the JSON data.

The method for converting the data format also has the following characteristics:

the step of constructing JSON data according to the two-dimensional table comprises the following steps: converting the information of each row of the two-dimensional table into one element in the JSON data respectively;

wherein converting information of a row of the two-dimensional table into one element of the JSON data comprises:

taking the specific value of the line head of the line as the value of the key field of the element corresponding to the line in the JSON data;

converting information of each column except a row header in the row into a common field in an element corresponding to the row in the JSON data, taking a code name corresponding to the information of the column header in a mapping pair of the column header in each column as a code name of the common field, constructing a specific value of the common field according to the content of each column of unit cells, converting a display name in the content of the column of unit cells into a code name as a specific value of the common field according to the mapping pair in the dictionary bound by the column for the column bound with the dictionary, and taking the content of the column of unit cells as the specific value of the common field for the column not bound with the dictionary.

The method for converting the data format also has the following characteristics:

the constructing of the two-dimensional table comprises:

determining an operation type of each column of the two-dimensional table; setting a dictionary bound with a column when the operation type of the column of the two-dimensional table is single selection; when the operation type of the column is single filling or multi filling, determining the data type of the column; setting a dictionary bound with the column when the operation type of the column is mapping and the data type is a non-object type; setting a dictionary which is bound with the column and comprises configuration items when the operation type of the column is mapping and the data type is an object type;

and aiming at each row of the two-dimensional table, setting the content of the cell corresponding to the row and the column according to the operation type of each column.

The method for converting the data format also has the following characteristics:

setting the content of the cell corresponding to the row and the column according to the operation type of each column comprises the following steps:

when the operation type of the column is single selection, selecting a mapping pair from the dictionary bound with the column, and taking the display name in the mapping pair as the content of the cell;

when the column operation type is multi-selection, selecting more than one mapping pair from the dictionary bound with the column, and taking the display name in the mapping pair as the content of the cell;

when the operation type of the column is mapping and the data type is non-object type, selecting more than one mapping pair from a dictionary bound with the column, taking the display name in the mapping pair as a key, and taking the specific value of each item input by a received user as the key value of the corresponding key;

when the operation type of the column is single filling, receiving information filled by a user;

when the operation type of the column is multi-filling, more than one item of information filled by the user is received.

The method for converting the data format also has the following characteristics:

the steps after the two-dimensional table is built and before the JSON data is built according to the two-dimensional table further comprise: adding a new column in the two-dimensional table, wherein the operation type of the column is mapping and the data type is object type, and setting a dictionary which is bound with the column and comprises configuration items;

the setting the content of the cell corresponding to the row and the column according to the operation type of each column comprises: setting the identification of the configuration item in the cell;

the constructing JSON data according to the two-dimensional table comprises the following steps: and setting elements, corresponding to the configuration items in the dictionary comprising the configuration items, of the configuration items contained in the two-dimensional table into the JSON data.

The device for converting data format in the invention comprises:

the dictionary construction module is used for constructing at least one dictionary, the dictionary comprises mapping pairs and/or configuration items, and the mapping pairs comprise display names and code names; the configuration items comprise information of elements corresponding to a row in JSON data corresponding to information of the row in a current table or other tables;

the table building module is used for building a two-dimensional table; setting a mapping pair of column headers of each column in the two-dimensional table, setting at least one column of the two-dimensional table to be bound with at least one dictionary, wherein the content of cells in the column bound with the dictionary comprises at least one display name;

the data construction module is used for constructing JSON data according to the two-dimensional table, wherein the construction of the JSON data according to the two-dimensional table comprises the following steps: and converting the display name contained in the two-dimensional table into the code name according to the mapping pair, and setting the code name in the JSON data.

The device for converting the data format also has the following characteristics:

the data construction module comprises an element construction unit, and is used for respectively converting the information of each row of the two-dimensional table into one element in the JSON data; specifically, the following method is used to convert the information of one row of the two-dimensional table into one element in the JSON data:

taking the specific value of the line head of the line as the value of the key field of the element corresponding to the line in the JSON data;

converting information of each column except a row header in the row into a common field in an element corresponding to the row in the JSON data, taking a code name corresponding to the information of the column header in a mapping pair of the column header in each column as a code name of the common field, constructing a specific value of the common field according to the content of each column of unit cells, converting a display name in the content of the column of unit cells into a code name as a specific value of the common field according to the mapping pair in the dictionary bound by the column for the column bound with the dictionary, and taking the content of the column of unit cells as the specific value of the common field for the column not bound with the dictionary.

The device for converting the data format also has the following characteristics:

the table building module comprises a type setting unit and a content setting module;

the type setting unit is used for determining the operation type of each column of the two-dimensional table; setting a dictionary bound with a column when the operation type of the column of the two-dimensional table is single selection; when the operation type of the column is single filling or multi filling, determining the data type of the column; setting a dictionary bound with the column when the operation type of the column is mapping and the data type is a non-object type; setting a dictionary which is bound with the column and comprises configuration items when the operation type of the column is mapping and the data type is an object type;

and the content setting module is used for setting the content of the cell corresponding to each row and column according to the operation type of each column aiming at each row of the two-dimensional table.

The device for converting the data format also has the following characteristics:

the content setting module is further configured to set the content of the cell corresponding to the row and the column according to the operation type of each column by using the following method:

when the operation type of the column is single selection, selecting a mapping pair from the dictionary bound with the column, and taking the display name in the mapping pair as the content of the cell;

when the column operation type is multi-selection, selecting more than one mapping pair from the dictionary bound with the column, and taking the display name in the mapping pair as the content of the cell;

when the operation type of the column is mapping and the data type is non-object type, selecting more than one mapping pair from a dictionary bound with the column, taking the display name in the mapping pair as a key, and taking the specific value of each item input by a received user as the key value of the corresponding key;

when the operation type of the column is single filling, receiving information filled by a user;

when the operation type of the column is multi-filling, more than one item of information filled by the user is received.

The device for converting the data format also has the following characteristics:

the table correction module is used for adding a new column in the two-dimensional table, wherein the operation type of the column is mapping and the data type is object type, and a dictionary which is bound with the column and comprises configuration items is set; the dictionary comprising the configuration items comprises identifications of the configuration items, and the configuration items comprise information of elements corresponding to a row in JSON data corresponding to information of the row in a current table or other tables;

the content setting module is also used for setting the identification of the configuration item in the cell;

the data construction module is further configured to set elements, corresponding to the configuration items included in the two-dimensional table, in the dictionary including the configuration items in the JSON data.

The advantages of the invention include:

firstly, the table is used for displaying data, the effect is more visual, the understanding is more convenient, and the method is particularly suitable for non-technical personnel to construct JSON data.

And secondly, the mapping of the dictionary is used for communicating the display of the table and the analysis of JSON, so that no trouble is caused on the display, and the JSON generation is not influenced.

And thirdly, the table setting does not lose the expressiveness of any JSON, and the situation that the JSON can be written out but the corresponding table cannot be configured does not occur. The tables and JSON are identical in expression capability.

Drawings

The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate an embodiment of the invention and, together with the description, serve to explain the invention and not to limit the invention. In the drawings:

FIG. 1 is a flow chart of a method of performing data format conversion in an embodiment;

FIG. 2 is a schematic diagram of JSON data in the first embodiment;

FIG. 3 is a schematic diagram of JSON data in the second embodiment;

fig. 4 is a block diagram of an apparatus for performing data format conversion in the embodiment.

Detailed Description

In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention. It should be noted that the embodiments and features of the embodiments in the present application may be arbitrarily combined with each other without conflict.

The applicant finds that table two-dimensional data is easy to understand, and if the table data can be serialized into JSON data, specifically, the table data is serialized into JSON data, a data interaction channel between a general user and a computer system can be realized, so that the use threshold of JSON is greatly reduced, and the data interaction efficiency between the user and the computer system is improved.

As shown in fig. 1, the method for converting the data format includes:

step 101, constructing at least one dictionary, wherein the dictionary comprises mapping pairs and/or configuration items, and the mapping pairs comprise display names and code names; the configuration items comprise information of elements corresponding to a row in JSON data corresponding to the information of the row in the current table or other tables;

102, constructing a two-dimensional table; setting a mapping pair of column headers of each column in the two-dimensional table, setting at least one column of the two-dimensional table to be bound with at least one dictionary, wherein the content of the cells in the column bound with the dictionary comprises at least one display name.

103, constructing JSON data according to the two-dimensional table, wherein the constructing the JSON data according to the two-dimensional table comprises the following steps: and converting the display name contained in the two-dimensional table into a code name according to the mapping pair, and setting the code name in the JSON data.

Wherein the content of the first and second substances,

specifically, converting the information of one row of the two-dimensional table into one element in JSON data includes: taking the specific value of the line head of the line as the value of the key field of the element corresponding to the line in the JSON data; converting information of each column except a row header in the row into a common field in an element corresponding to the row in JSON data, taking a code name corresponding to information of the column header in a mapping pair of the column header as a code name of the common field, constructing a specific value of the common field according to content of a unit cell of each column, converting a display name in the content of the unit cell of the column into the code name as a specific value of the common field according to the mapping pair in the dictionary bound by the column for the column bound with the dictionary, and taking the content of the unit cell of the column as the specific value of the common field for the column not bound with the dictionary.

In step 102, constructing a two-dimensional table includes:

substep 1, determining the operation type of each column of the two-dimensional table; when the operation type of one column of the two-dimensional table is single selection, a dictionary bound with the column is set; determining the data type of the column when the operation type of the column is single filling or multi filling; setting a dictionary bound with the column when the operation type of the column is mapping and the data type is a non-object type; setting a dictionary which is bound with the column and comprises configuration items when the operation type of the column is mapping and the data type is an object type;

and a substep 2, setting the content of the cell corresponding to each row and column according to the operation type of each column aiming at each row of the two-dimensional table.

There are 6 types of data: integer (int), real (float), string (string), boolean (boolean), null (null), object (object).

The dictionary in the method is an array formed by mapping pairs, each mapping pair must contain 2 attributes, namely a common name (name) used for displaying on a table, and a code name (code _ name) used for being used as a field value field in JSON data. The dictionary can be manually input and configured by a user, and can also be automatically generated by reading other APIs.

16页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种用于教学系统的共案课件制作方法、装置和终端

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!