Method and device for constructing JSON formatted data

文档序号:1215798 发布日期:2020-09-04 浏览:6次 中文

阅读说明:本技术 一种构建json格式化数据的方法及装置 (Method and device for constructing JSON formatted data ) 是由 田津津 万振 赵鹏 于 2019-02-28 设计创作,主要内容包括:本发明公开了一种构建JSON格式化数据的方法及装置,此方法包括:监听文本输入区域的输入操作,获取所述文本输入区域的输入信息,判断所述输入信息是否符合JSON格式标准,所述输入信息符合JSON格式标准时,将所述输入信息根据所述JSON格式标准转换为JSON格式数据;所述输入信息不符合JSON格式标准时,提示所述输入信息中导致输入信息不符合JSON格式标准的部分。本发明集多种JSON编辑器的优点于一身,操作简便、富有实用性和易用性,可以应用于绝大数JSON数据格式的设计和分析场景。(The invention discloses a method and a device for constructing JSON formatted data, wherein the method comprises the following steps: monitoring input operation of a text input area, acquiring input information of the text input area, judging whether the input information meets JSON format standards, and converting the input information into JSON format data according to the JSON format standards when the input information meets the JSON format standards; and prompting the part of the input information, which causes the input information not to conform to the JSON format standard, when the input information does not conform to the JSON format standard. The method integrates the advantages of multiple JSON editors, is simple and convenient to operate, is high in practicability and usability, and can be applied to the design and analysis scenes of most JSON data formats.)

1. A method for constructing JSON formatted data, comprising:

monitoring input operation of a text input area, acquiring input information of the text input area, judging whether the input information meets JSON format standards, and converting the input information into JSON format data according to the JSON format standards when the input information meets the JSON format standards; and prompting the part of the input information, which causes the input information not to conform to the JSON format standard, when the input information does not conform to the JSON format standard.

2. The method of constructing JSON formatted data according to claim 1,

the judging whether the input information conforms to the JSON format standard comprises the following steps:

performing the operation of converting the character string into the JSON object on the text content in the editing area by a method of converting the character string into the JSON object;

if the operation of converting the character string into the JSON object is not abnormal, the text content in the editor is expressed to be in a standard JSON format;

if the operation output of the character string to JSON object is abnormal, executing the text content in the editing area by executing a function;

if the output of the execution function is abnormal, the text content in the editor is not in a standard JSON format;

if the execution function does not output an exception, performing JSON object to character string operation on the execution result of the execution function by a JSON object to character string method;

if the operation of converting the JSON object into the character string returns the character string, the text in the editor is expressed to be in a standard JSON format;

and if the operation of converting the JSON object into the character string returns undefined information, the text in the editor is not in a standard JSON form.

3. The method of constructing JSON formatted data according to claim 1,

the input operation of monitoring the text input area comprises the following steps: and monitoring whether the input operation of the text input area is a line feed operation, determining the position of the line feed operation in JSON format data corresponding to the position in the input text after monitoring the line feed operation, and executing indentation operation of a preset number of blank spaces at the position.

4. The method of constructing JSON formatted data according to claim 1,

the method further comprises the following steps:

monitoring a trigger signal of a split screen button;

after a trigger signal to a split screen button is monitored, copying the processing logic of part or all of tags in an original editing area and the processing logic of a text input area, wherein the tags comprise a JSON data tag and a function tag which are parallel;

the display area is divided into two editing areas, the first editing area is maintained by using the processing logic of the label and the text input area in the original editing area, and the second editing area is maintained by using the processing logic of the copied label and the text input area.

5. The method of constructing JSON formatted data according to claim 1,

the method further comprises the following steps:

monitoring a trigger signal for adding a new button control;

and after monitoring a trigger signal for adding a new button control, adding a new button, and setting a click event corresponding to the button.

6. The method of constructing JSON formatted data according to claim 1,

monitoring the change of the input content of the user, and storing the input content of the user and the state of each component in the editor when the change of the input content of the user reaches a change threshold;

and when the editor is restarted accidentally, loading the saved user input content and the states of all components in the editor.

7. An apparatus for constructing JSON formatted data, comprising:

the monitoring module is used for monitoring the input operation of a text input area and acquiring the input information of the text input area;

the grammar judging module is used for judging whether the input information conforms to the JSON format standard;

the conversion module is used for converting the input information into JSON format data according to the JSON format standard when the input information conforms to the JSON format standard;

and the prompting module is used for prompting the part of the input information, which causes the input information not to conform to the JSON format standard, when the input information does not conform to the JSON format standard.

8. The apparatus for constructing JSON formatted data according to claim 7,

the grammar judging module is also used for judging whether the input information conforms to the JSON format standard by using the following method:

performing the operation of converting the character string into the JSON object on the text content in the editing area by a method of converting the character string into the JSON object;

if the operation of converting the character string into the JSON object is not abnormal, the text content in the editor is expressed to be in a standard JSON format;

if the operation output of the character string to JSON object is abnormal, executing the text content in the editing area by executing a function;

if the output of the execution function is abnormal, the text content in the editor is not in a standard JSON format;

if the execution function does not output an exception, performing JSON object to character string operation on the execution result of the execution function by a JSON object to character string method;

if the operation of converting the JSON object into the character string returns the character string, the text in the editor is expressed to be in a standard JSON format;

and if the operation of converting the JSON object into the character string returns undefined information, the text in the editor is not in a standard JSON form.

9. The apparatus for constructing JSON formatted data according to claim 7,

the apparatus also includes a format beautification module;

the monitoring module is further configured to monitor whether an input operation of the text input area is a line feed operation;

and the format beautifying module is used for determining the position of the line feed operation in JSON format data corresponding to the position of the input text after the monitoring module monitors the line feed operation, and executing indentation operation of a preset number of blank spaces at the position.

10. The apparatus for constructing JSON formatted data according to claim 7,

the device also comprises an interface processing module;

the monitoring module is also used for monitoring a trigger signal of the screen split button;

the interface processing module is also used for copying the processing logic of part or all of tags in the original editing area and the processing logic of the text input area after the monitoring module monitors a trigger signal of the split screen button, wherein the tags comprise a JSON data tag and a function tag which are parallel; the display area is divided into two editing areas, the first editing area is maintained by using the processing logic of the label and the text input area in the original editing area, and the second editing area is maintained by using the processing logic of the copied label and the text input area.

11. The apparatus for constructing JSON formatted data according to claim 7,

the device also comprises an interface processing module;

the monitoring module is also used for monitoring a trigger signal for adding a new button control;

the interface processing module is further configured to add a new button after the monitoring module monitors the trigger signal for adding the new button control, and set a click event corresponding to the button.

12. The apparatus for constructing JSON formatted data according to claim 7,

the device also comprises a storage module and a reconstruction module;

the monitoring module is also used for monitoring the change of the input content of the user;

the storage module is used for storing the user input content and the state of each component in the editor when the change of the user input content reaches a change threshold;

and the reconstruction module is used for loading the saved user input content and the states of all components in the editor when the editor is restarted unexpectedly.

Technical Field

The invention relates to the technical field of data processing, in particular to a method and a device for constructing JSON formatted data.

Background

JSON is a lightweight data exchange format, can exchange data between different platforms, is a mainstream data exchange format at present instead of XML due to good characteristics of being readable and convenient to write quickly, and is applied to various data exchange scenes.

Although JSON syntax is simple and can be written using a general text editor, for writing JSON data having a complicated structure, the operation using a general text editor is cumbersome, the function of the general text editor is simple, and operation errors and editing errors are liable to occur.

For example: in the prior art, when a certain web application interface is successfully called directly through a browser or messy JSON data from background response is obtained in a web debugging mode of the browser, the JSON data needs to be formatted into a clear structure so as to be convenient for analysis. Although the existing JSON editor can also format a messy JSON structure, the processing mode is not simple enough. Usually, a mouse is used for selecting a JSON character string on a browser, and the JSON character string is copied to a JSON editor; and clicking a related button on a JSON editor interface to format the JSON character string. At least the two steps are needed to format the disordered JSON data into a clear-structured form, and the operation is not concise enough.

Disclosure of Invention

In order to solve the technical problem, the invention provides a method and a device for constructing JSON formatted data.

The method for constructing JSON formatted data provided by the invention comprises the following steps:

monitoring input operation of a text input area, acquiring input information of the text input area, judging whether the input information meets JSON format standards, and converting the input information into JSON format data according to the JSON format standards when the input information meets the JSON format standards; and prompting the part of the input information, which causes the input information not to conform to the JSON format standard, when the input information does not conform to the JSON format standard.

Further, the method for constructing the JSON formatted data has the following characteristics:

the judging whether the input information conforms to the JSON format standard comprises the following steps:

performing the operation of converting the character string into the JSON object on the text content in the editing area by a method of converting the character string into the JSON object;

if the operation of converting the character string into the JSON object is not abnormal, the text content in the editor is expressed to be in a standard JSON format;

if the operation output of the character string to JSON object is abnormal, executing the text content in the editing area by executing a function;

if the output of the execution function is abnormal, the text content in the editor is not in a standard JSON format;

if the execution function does not output an exception, performing JSON object to character string operation on the execution result of the execution function by a JSON object to character string method;

if the operation of converting the JSON object into the character string returns the character string, the text in the editor is expressed to be in a standard JSON format;

and if the operation of converting the JSON object into the character string returns undefined information, the text in the editor is not in a standard JSON form.

Further, the method for constructing the JSON formatted data has the following characteristics:

the input operation of monitoring the text input area comprises the following steps: and monitoring whether the input operation of the text input area is a line feed operation, determining the position of the line feed operation in JSON format data corresponding to the position in the input text after monitoring the line feed operation, and executing indentation operation of a preset number of blank spaces at the position.

Further, the method for constructing the JSON formatted data has the following characteristics:

the method further comprises the following steps:

monitoring a trigger signal of a split screen button;

after a trigger signal to a split screen button is monitored, copying the processing logic of part or all of tags in an original editing area and the processing logic of a text input area, wherein the tags comprise a JSON data tag and a function tag which are parallel;

the display area is divided into two editing areas, the first editing area is maintained by using the processing logic of the label and the text input area in the original editing area, and the second editing area is maintained by using the processing logic of the copied label and the text input area.

Further, the method for constructing the JSON formatted data has the following characteristics:

the method further comprises the following steps:

monitoring a trigger signal for adding a new button control;

and after monitoring a trigger signal for adding a new button control, adding a new button, and setting a click event corresponding to the button.

Further, the method for constructing the JSON formatted data has the following characteristics:

monitoring the change of the input content of the user, and storing the input content of the user and the state of each component in the editor when the change of the input content of the user reaches a change threshold;

and when the editor is restarted accidentally, loading the saved user input content and the states of all components in the editor.

The device for constructing JSON formatted data provided by the invention comprises:

the monitoring module is used for monitoring the input operation of a text input area and acquiring the input information of the text input area;

the grammar judging module is used for judging whether the input information conforms to the JSON format standard;

the conversion module is used for converting the input information into JSON format data according to the JSON format standard when the input information conforms to the JSON format standard;

and the prompting module is used for prompting the part of the input information, which causes the input information not to conform to the JSON format standard, when the input information does not conform to the JSON format standard.

Further, the device for constructing the JSON formatted data has the following characteristics:

the grammar judging module is also used for judging whether the input information conforms to the JSON format standard by using the following method:

performing the operation of converting the character string into the JSON object on the text content in the editing area by a method of converting the character string into the JSON object;

if the operation of converting the character string into the JSON object is not abnormal, the text content in the editor is expressed to be in a standard JSON format;

if the operation output of the character string to JSON object is abnormal, executing the text content in the editing area by executing a function;

if the output of the execution function is abnormal, the text content in the editor is not in a standard JSON format;

if the execution function does not output an exception, performing JSON object to character string operation on the execution result of the execution function by a JSON object to character string method;

if the operation of converting the JSON object into the character string returns the character string, the text in the editor is expressed to be in a standard JSON format;

and if the operation of converting the JSON object into the character string returns undefined information, the text in the editor is not in a standard JSON form.

Further, the device for constructing the JSON formatted data has the following characteristics:

the apparatus also includes a format beautification module;

the monitoring module is further configured to monitor whether an input operation of the text input area is a line feed operation;

and the format beautifying module is used for determining the position of the line feed operation in JSON format data corresponding to the position of the input text after the monitoring module monitors the line feed operation, and executing indentation operation of a preset number of blank spaces at the position.

Further, the device for constructing the JSON formatted data has the following characteristics:

the device also comprises an interface processing module;

the monitoring module is also used for monitoring a trigger signal of the screen split button;

the interface processing module is also used for copying the processing logic of part or all of tags in the original editing area and the processing logic of the text input area after the monitoring module monitors a trigger signal of the split screen button, wherein the tags comprise a JSON data tag and a function tag which are parallel; the display area is divided into two editing areas, the first editing area is maintained by using the processing logic of the label and the text input area in the original editing area, and the second editing area is maintained by using the processing logic of the copied label and the text input area.

Further, the device for constructing the JSON formatted data has the following characteristics:

the device also comprises an interface processing module;

the monitoring module is also used for monitoring a trigger signal for adding a new button control;

the interface processing module is further configured to add a new button after the monitoring module monitors the trigger signal for adding the new button control, and set a click event corresponding to the button.

Further, the device for constructing the JSON formatted data has the following characteristics:

the device also comprises a storage module and a reconstruction module;

the monitoring module is also used for monitoring the change of the input content of the user;

the storage module is used for storing the user input content and the state of each component in the editor when the change of the user input content reaches a change threshold;

and the reconstruction module is used for loading the saved user input content and the states of all components in the editor when the editor is restarted unexpectedly.

The method integrates the advantages of multiple JSON editors, is simple and convenient to operate, is high in practicability and usability, and can be applied to the design and analysis scenes of most JSON data formats.

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 constructing JSON formatted data;

fig. 2 is a block diagram of a method of constructing JSON-formatted data.

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.

As shown in fig. 1, the method of constructing JSON formatted data includes:

step 101, monitoring input operation of a text input area, and acquiring input information of the text input area;

step 102, judging whether the input information meets JSON format standard;

step 103, converting the input information into JSON format data according to the JSON format standard when the input information meets the JSON format standard; and prompting the part of the input information, which causes the input information not to conform to the JSON format standard, when the input information does not conform to the JSON format standard.

Wherein the content of the first and second substances,

in step 101, the monitoring the input operation of the text input area includes: monitoring whether the input operation of the text input area is a line feed operation, after the line feed operation is monitored, determining the position of the line feed operation in JSON format data corresponding to the position in the input text, and executing indentation operation of a preset number of blank spaces at the position. In a conventional editor in the prior art, when the JSON format data needs to be indented, the indentation is manually controlled. In contrast to this prior art approach, the present invention can accomplish automatic retraction. The starting manner of the monitoring text input area may be to click a control of the editor interface for indicating whether to start the monitoring function (for example, a check box of "monitoring text input area" is arranged on the editor interface, and after the check box is clicked, the monitoring is started, and after the check box is cancelled, the monitoring is prohibited).

The step 102 of judging whether the input information conforms to the JSON format standard includes:

performing an operation of converting the character string into the JSON object on the text content in the editing area by a method (for example, a parse method of the JSON object built in javascript) of converting the character string into the JSON object;

if the operation of converting the character string into the JSON object is not abnormal, the text content in the editor is expressed to be in a standard JSON format;

if the operation output of the character string to JSON object is abnormal, executing the text content in the editing area by executing a function (such as eval function of javascript);

if the output of the execution function is abnormal, the text content in the editor is not in a standard JSON format;

if the execution function does not output an exception, performing JSON object to character string operation on the execution result of the execution function by a JSON object to character string method (such as a striping method of a JSON object);

if the operation of converting the JSON object into the character string returns the character string, the text in the editor is expressed to be in a standard JSON format;

if the operation of the JSON object to convert the character string returns undefined, the text in the editor is not represented as a standard JSON formula.

In step 103, when the input information does not meet the JSON format standard, the part of the input information, which causes the input information to not meet the JSON format standard, is determined according to an abnormal information positioning mode when the input information is abnormal by a method (for example, a parse method of a JSON object built in javascript) for converting a character string into the JSON object.

The method also comprises the following steps: monitoring a trigger signal of a split screen button; after a trigger signal to a split screen button is monitored, copying the processing logic of part or all of tags in an original editing area and the processing logic of a text input area, wherein the tags comprise a JSON data tag and a function tag which are parallel; the display area is divided into two editing areas, the first editing area is maintained by using the processing logic of the label and the text input area in the original editing area, and the second editing area is maintained by using the processing logic of the copied label and the text input area. For example: once the 'split screen button' is clicked, a split screen click event is triggered, so that a corresponding code is executed, the length and width of a screen are calculated through parameters set in the code, and finally an editable area is added in a current interface. In the process of using by a user, a plurality of JSON data are often needed to be compared, analyzed and modified simultaneously. However, the existing JSON editor provides only one editing area on the interface at most, and cannot meet the requirement. The method can solve the requirement, divides one editing area in the interface into two editing areas, can simultaneously edit or analyze and compare two JSON data in one display interface, and greatly improves the practicability of the editor. Each split screen can simultaneously create a plurality of tags for processing through an event isolation technology between processing logics in charge of different tags, so that editors corresponding to any tag of any screen do not have any association and do not generate any interference.

The method also comprises the following steps: monitoring a trigger signal for adding a new button control; and after monitoring a trigger signal for adding a new button control, adding a new button, and setting a click event corresponding to the button. For example: the graphic interface module provides a corresponding 'add label' button, and the background provides a click event corresponding to the button and a processing method thereof. Once the "add label" button is clicked or the label bar is double-clicked, a click event of "add label" is triggered, so that a corresponding method is executed to initialize a new label object, and finally a new label is added on the interface.

The method also comprises the following steps:

monitoring the change of the input content of the user, and storing the input content of the user and the state of each component in the editor when the change of the input content of the user reaches a change threshold; and when the editor is restarted accidentally, loading the saved user input content and the states of all components in the editor. For example: when the input change of the user reaches a certain threshold (for example, 10 characters), the program automatically saves the input content to the local IndexedDB database, and when the page is closed accidentally, the newly saved data is automatically extracted from the IndexedDB and displayed to the input box.

Specific examples are as follows:

under the condition that the browser supports indexDB, after a program of the method is started, the program judges whether a database of indexDB needs to be created or not, if the database exists, the database information is read out and subsequent processing is executed, otherwise, the database is created, and an Object Store is initialized under the database for storing label information of a current window and text information input by a user, wherein the label name is used as key, and characters in a text box in the label are used as value.

On a text editing page, an editor monitoring module monitors whether the input of a user reaches a threshold value set by a program; once the threshold is reached, the program calls the code to execute the step (A), otherwise, the monitoring is continued;

step (A), when the data in the text box reaches a program threshold value, the code responsible for processing the text memory function calls a text storage code: reading all label objects in a current window, and counting the number of labels; traversing the label object, reading the name of the label object and the text data in the text box, taking the label name as a key, taking the text content corresponding to the label as a value, and storing the label name key and the text content value into an indexDB database in the process of traversing the label object.

And (4) when the page of the editor is normally closed or is closed carelessly, after the editor is reopened, the program judges whether an indexDB database exists, reads out the data in the database under the condition that the database exists, and then calls a restore method provided in the graphical interface module to reconstruct the page.

When the page is reconstructed, the encapsulated restore method is used for traversing data (including a tag name and text content) read from an indexDB database, then a self-defined tag object is constructed, the tag name and the text content are assigned to the tag object, and the tag object is further rendered on the page to be displayed after assignment is finished, so that the functions of text memory and recovery are achieved.

This functionality is developed based on the HTML5 standard, and enables instant saving of editor content via the client database indexedb, without loss of user input even if the user inadvertently closes the browser, or the browser crashes unexpectedly. The problem that in a JSON editor in the prior art, after a user closes a page carelessly, previously designed JSON data is lost, and the previously edited data cannot be recovered even if a 'tag closed last time' function is recovered through a browser is solved.

The method can also automatically beautify JSON structure data, and improve the use experience of users. For example: judging key and value in the JSON structure data, and highlighting the key and the value in different colors, for example, displaying the key in red and displaying the value in blue to highlight the key-value pair relation of the JSON data. The highlighting function and the grammar detection function can be simultaneously carried out, and the highlighting is not carried out because of JSON grammar errors. Besides the highlighting mode, the method can also execute the beautifying mode of automatically controlling the character space, so that the final JSON format data presents the effects of tidiness and beauty.

The method integrates the advantages of multiple JSON editors, is simple and convenient to operate, is high in practicability and usability, and can be applied to the design and analysis scenes of most JSON data formats.

The above-described aspects may be implemented individually or in various combinations, and such variations are within the scope of the present invention.

It will be understood by those skilled in the art that all or part of the steps of the above methods may be implemented by instructing the relevant hardware through a program, and the program may be stored in a computer readable storage medium, such as a read-only memory, a magnetic or optical disk, and the like. Alternatively, all or part of the steps of the foregoing embodiments may also be implemented by using one or more integrated circuits, and accordingly, each module/unit in the foregoing embodiments may be implemented in the form of hardware, and may also be implemented in the form of a software functional module. The present invention is not limited to any specific form of combination of hardware and software.

It is to be noted that, in this document, the terms "comprises", "comprising" or any other variation thereof are intended to cover a non-exclusive inclusion, so that an article or apparatus including a series of elements includes not only those elements but also other elements not explicitly listed or inherent to such article or apparatus. Without further limitation, an element defined by the phrase "comprising … …" does not exclude the presence of additional like elements in the article or device comprising the element.

The above embodiments are merely to illustrate the technical solutions of the present invention and not to limit the present invention, and the present invention has been described in detail with reference to the preferred embodiments. It will be understood by those skilled in the art that various modifications and equivalent arrangements may be made without departing from the spirit and scope of the present invention and it should be understood that the present invention is to be covered by the appended claims.

11页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种开放式企业级信息系统的信息转换方法

网友询问留言

已有0条留言

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

精彩留言,会给你点赞!