CN114760374A - Message parsing method and device, electronic equipment and medium - Google Patents
Message parsing method and device, electronic equipment and medium Download PDFInfo
- Publication number
- CN114760374A CN114760374A CN202210288882.0A CN202210288882A CN114760374A CN 114760374 A CN114760374 A CN 114760374A CN 202210288882 A CN202210288882 A CN 202210288882A CN 114760374 A CN114760374 A CN 114760374A
- Authority
- CN
- China
- Prior art keywords
- message
- sub
- key
- multipart
- type
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 69
- 230000014509 gene expression Effects 0.000 claims description 40
- 238000012545 processing Methods 0.000 claims description 25
- 238000004590 computer program Methods 0.000 claims description 22
- 238000000638 solvent extraction Methods 0.000 claims description 11
- 238000012216 screening Methods 0.000 claims description 2
- 238000004458 analytical method Methods 0.000 abstract description 6
- 238000010586 diagram Methods 0.000 description 10
- 230000015654 memory Effects 0.000 description 10
- 238000004891 communication Methods 0.000 description 8
- 230000006870 function Effects 0.000 description 8
- 230000011218 segmentation Effects 0.000 description 5
- 230000004044 response Effects 0.000 description 4
- 230000003287 optical effect Effects 0.000 description 3
- 238000007781 pre-processing Methods 0.000 description 3
- 230000008569 process Effects 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000005192 partition Methods 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 239000000835 fiber Substances 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 238000004806 packaging method and process Methods 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 239000000758 substrate Substances 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/22—Parsing or analysis of headers
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/02—Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Security & Cryptography (AREA)
- Information Transfer Between Computers (AREA)
Abstract
The present disclosure provides a message parsing method, which can be applied to the technical field of the internet. The message analysis method comprises the following steps: dividing first entity information of the multipart type message into at least two sections of sub-messages according to a first divider in first header information of the multipart type message; determining key names and key values respectively corresponding to at least two sections of sub-messages; and generating a JSON object of the multipart type message according to the key name and the key value. The present disclosure also provides a packet parsing apparatus, device, storage medium, and program product, which can be used for parsing multipart type packets in the financial field or other fields.
Description
Technical Field
The present disclosure relates to the field of internet technologies, and in particular, to an HTTP message, and more particularly, to a method, an apparatus, a device, and a medium for parsing a message, which may be used for parsing a multipart type message in the financial field or other fields.
Background
The Web over the internet is based on the HTTP protocol for communication between the client and the server, which specifies that a request is sent from the client, and finally the server responds to the request and returns it. Information used for HTTP protocol interaction is called an HTTP message, the HTTP message of a request end (client) is called a request message, the HTTP message of a response end (server) is called a response message, and the HTTP message is composed of a message header, an empty line and a message body. The MIME is adopted in the HTTP message, which allows processing a plurality of different types of data such as text, pictures, video and the like, the markup data types can be described by using the MIME, while a method called multipart object set (multipart) is used in the MIME extension to accommodate a plurality of different types of data, mainly comprising multipart/form-data (which can be used for sending information from an HTML form to a server from a browser) and multipart/bytes (which can be used for sending partial response messages back to the browser, and the MIME is used for indicating that the file is composed of a plurality of parts, each of which has a request range and is mainly used for large data block transmission at a slow network speed).
Unfortunately, the current native javascript XMLHttpRequest and some mainstream ajax class libraries have the defects that only the message with the MIME type being application/json type can be analyzed, but the message with the multipart type cannot be analyzed, so that the application of the message with the multipart type is limited.
Disclosure of Invention
In view of the foregoing, the present disclosure provides a message parsing method, apparatus, device, medium, and program product.
According to a first aspect of the present disclosure, a method for parsing a packet is provided, including: dividing first entity information of the multipart type message into at least two sections of sub-messages according to a first divider in first header information of the multipart type message; determining key names and key values respectively corresponding to at least two sections of sub-messages; and generating a JSON object of the message of the multipart type according to the key name and the key value.
According to the embodiment of the present disclosure, determining the key name and the key value respectively corresponding to at least two segments of sub-messages includes: and determining a key name according to the second head information of the sub-message, and determining a key value according to the second entity information of the sub-message.
According to an embodiment of the present disclosure, the dividing the first entity information of the multipart type packet into at least two segments of sub-packets according to the first divider in the first header information of the multipart type packet includes: constructing a first regular expression according to the first separator, wherein the first separator at least comprises a boundary field; and dividing the first entity information into at least two segments of sub-messages according to the first regular expression.
According to the embodiment of the present disclosure, segmenting the first entity information into at least two segments of sub-packets according to the first regular expression includes: obtaining at least two placeholders of the first entity information according to the first regular expression; and dividing the message into a first array according to the at least two placeholders, wherein the first array comprises at least two sections of sub-messages.
According to the embodiment of the present disclosure, determining a key name according to the second header information of the sub-packet, and determining a key value according to the second entity information of the sub-packet includes: dividing the sub-message into second header information and second entity information according to a second separator in the sub-message; obtaining a second regular expression according to the second head information; processing the second head information by using a second regular expression to obtain a key name; and dividing the second entity information into a second array by using the row division character, wherein the first bit of the second array is a key value.
According to the embodiment of the disclosure, the step of generating the JSON object of the multipart type message according to the key name and the key value comprises: creating an empty object; and recording key names corresponding to at least two segments of sub-messages in the empty object, and respectively assigning the key values corresponding to the at least two segments of sub-messages to the key names corresponding to the at least two segments of sub-messages to generate the JSON object of the multipart type message.
According to an embodiment of the present disclosure, obtaining the second regular expression according to the second header information includes: detecting the type of the multipart type message; if the message of the multipart type is of the multipart/form-data type, constructing a second regular expression according to the name field in the second header information; and if the message of the multipart type is of the multipart/bytes type, constructing a second regular expression according to the bytes field in the second header information.
According to the embodiment of the present disclosure, the message parsing method further includes: receiving an HTTP request message; screening a multipart type message according to the header information of the HTTP request message; and detecting whether the first entity information of the message is of a character type, and if the entity information is not of the character type, converting the first entity information into the character type.
A second aspect of the present disclosure provides a packet parsing apparatus, including: the partitioning module is used for partitioning the first entity information of the multipart type message into at least two segments of sub-messages according to a first partitioning symbol in the first header information of the multipart type message; the key name key value module is used for determining the key name and the key value respectively corresponding to the at least two sections of sub-messages; and the object module is used for generating a JSON object of the multipart type message according to the key name and the key value.
A third aspect of the present disclosure provides an electronic device, comprising: one or more processors; a memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the message parsing method described above.
A fourth aspect of the present disclosure also provides a computer-readable storage medium having stored thereon executable instructions, which, when executed by a processor, cause the processor to perform the above-mentioned message parsing method.
A fifth aspect of the present disclosure also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the computer program implements the message parsing method.
Drawings
The foregoing and other objects, features and advantages of the disclosure will be apparent from the following description of embodiments of the disclosure, which proceeds with reference to the accompanying drawings, in which:
fig. 1 schematically illustrates an application scenario diagram of a message parsing method, apparatus, device, medium, and program product according to an embodiment of the present disclosure;
fig. 2 schematically illustrates a flow chart of a message parsing method according to an embodiment of the present disclosure;
FIG. 3 schematically illustrates a flow chart of a method of segmenting a message according to an embodiment of the present disclosure;
FIG. 4 schematically illustrates a flow chart of a method of creating a first array in accordance with an embodiment of the disclosure;
fig. 5 schematically shows a flow chart of a method of determining a key name and a key value according to an embodiment of the present disclosure;
FIG. 6 schematically illustrates a flow chart of a method of message pre-processing according to an embodiment of the present disclosure;
fig. 7 schematically shows a block diagram of a structure of a message parsing apparatus according to an embodiment of the present disclosure; and
fig. 8 schematically shows a block diagram of an electronic device adapted to implement a message parsing method according to an embodiment of the present disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is illustrative only and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. Moreover, in the following description, descriptions of well-known structures and techniques are omitted so as to not unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs, unless otherwise defined. It is noted that the terms used herein should be interpreted as having a meaning that is consistent with the context of this specification and should not be interpreted in an idealized or overly formal sense.
Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B and C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
The embodiment of the disclosure provides a message parsing method, which is used for solving the problem that response data returned by an HTTP request multi-type (multipart) cannot be processed and parsed by an XMLHttpRequest of native JavaScript and a plurality of mainstream ajax class libraries, namely a method for parsing and processing a multipart type message.
JavaScript (JS) is a lightweight, interpreted or just-in-time programming language with function preference, often used as a scripting language for developing web pages. XMLHttpRequest is a set of API functions that can be called by JavaScript, JScript, VBScript, and other scripting languages embedded in web browsers.
Ajax, Asynchronous Javascript And XML, is used to describe a new method using a prior art collection. Using the ajax technology web application can quickly present incremental updates on a user interface without reloading the entire web page.
For multipart type messages, the information used for HTTP protocol interaction is called HTTP messages, and the HTTP messages are composed of header information and entity information, and the HTTP messages adopt a MIME mechanism. MIME, also known as media type, is a standard that specifies a symbolization method for representing various data types, such as "application/json", for representing the nature and format of a document, file, or byte stream. Thus, HTTP messages allow for the processing of many different types of data, such as text, pictures, video, and the like. In the MIME extension, a method called multipart object set (multipart) is used to accommodate a plurality of different types of data, and multipart type messages are formed, mainly comprising multipart/form-data and multipart/bytearges.
It should be noted that the message parsing method and apparatus provided by the present disclosure may be used for parsing a message transmitted by using an HTTP protocol in the internet in the financial field, and may also be used for parsing a message transmitted by using an HTTP protocol in the internet in any field other than the financial field.
Fig. 1 schematically illustrates an application scenario diagram of a message parsing method, apparatus, device, medium, and program product according to an embodiment of the present disclosure.
As shown in fig. 1, an application scenario 100 according to this embodiment may include that a user may send a request to a server by using a terminal, the server may receive a client request and return related resource information to the client, and the client performs parsing processing on a returned message. Network 102 is the medium used to provide communication links between terminal equipment 101 and server 103. Network 102 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may use terminal device 101 to interact with server 103 via network 102 to send requests, receive messages, and the like. Various front-end applications may be installed on the terminal device 101 to parse the message.
The terminal device 101 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 103 may be a server that provides various services, such as a background management server that provides support for requests sent by users using the terminal devices 101. The backend management server may analyze and process the received data such as the user request, and feed back a processing result (for example, a web page, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that the message parsing method provided in the embodiment of the present disclosure may be generally executed by the terminal device 101. Accordingly, the message parsing apparatus provided in the embodiment of the present disclosure may be generally disposed in the terminal device 101. The message parsing method provided by the embodiment of the present disclosure may also be executed by the server 103. Correspondingly, the message parsing apparatus provided in the embodiment of the present disclosure may also be disposed in the server 103. The message parsing method provided in the embodiment of the present disclosure may also be executed by a server or a server cluster that is different from the server 103 and is capable of communicating with the terminal device 101 and/or the server 103. Correspondingly, the message parsing apparatus provided in the embodiment of the present disclosure may also be disposed in a server or a server cluster that is different from the server 103 and is capable of communicating with the terminal device 101 and/or the server 103.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The following describes in detail a packet parsing method according to the disclosed embodiment with reference to fig. 2 to 6 based on the scenario described in fig. 1.
Fig. 2 schematically shows a flow chart of a message parsing method according to an embodiment of the present disclosure.
As shown in fig. 2, the message parsing method of this embodiment includes operations S201 to S203, and the message parsing method may be executed by a front end located at a client.
In operation S201, the first entity information of the multipart type packet is divided into at least two sub-packets according to the first divider in the first header information of the multipart type packet.
In operation S202, a key name and a key value respectively corresponding to at least two segments of sub-packets are determined.
In operation S203, a JSON object of the multipart type packet is generated according to the key name and the key value.
In a specific embodiment of the present disclosure, a user sends 2 types of data including text and pictures including transaction information, authentication images, and the like to a server by using a financial client of a web page, and the data is sent to the server in the form of a multipart/form-data message in the form of an HTML form, and the server parses the message. The server obtains a first delimiter, for example, a "boundary" - - -character string ", from the header information, i.e., the first header information, of the multipart/form-data packet, and divides the main packet into 2 sub-packets by identifying the first delimiter. Each sub-message comprises a key name and a key value, 2 corresponding key names and 2 corresponding key values are confirmed from 2 segments of sub-messages respectively, the key names represent data names of the sub-messages, and the key values represent data values of the sub-messages.
JSON, a lightweight data exchange format, is a character string representation of an object in a JavaScript programming language, and the format { key1: value1, key2: value 2. } comprises a JSON object and a JSON character string which can be mutually converted, wherein a key value can be directly called in the JSON object according to a key name. According to the method, after 2 corresponding key names and 2 corresponding key values are obtained, the key names and the key values are used for generating the JSON object of the message of the multipart type. The message of the multipart type is analyzed into the JSON object, a data structure of the message is shown, the message can be directly used as an object in JavaScript for processing and calling, the technical problem indicated in the disclosure is solved, and meanwhile, the JSON object is more convenient to process and call, and the processing and browsing of data are facilitated.
Fig. 3 schematically shows a flow chart of a method of segmenting a message according to an embodiment of the present disclosure.
As shown in fig. 3, the method for segmenting a message according to this embodiment includes operations S301 to S302.
In operation S301, a first regular expression is constructed according to a first divider, the first divider including at least a boundary field.
In operation S302, the first entity information is segmented into at least two segments of sub-packets according to the first regular expression.
When the multipart Type message is used, a Content-Type (internet media Type) note is added to a header information field, and the message contains a MIME Type and a multipart object segmentation symbol, such as Content-Type: multipart/form-data; a boundary-boundary string (a string starting from a' e.g., boundary-8612647898745) divides a multipart type message into various entities as different components, and each component has its own entity information and header information. The present disclosure constructs a first regular expression from a first divider comprising a boundary field, for example: (/ boundary ═ (. A Regular Expression (Regular Expression) is a text pattern that includes normal characters (e.g., letters between a and z) and special characters (called "meta characters"). Regular expressions use a single string to describe, match a series of strings that match a certain syntactic rule. By utilizing the first regular expression, the first entity information of the main message is divided into at least two segments of sub-messages, so that the efficiency and the accuracy of the division processing are improved, and the message analysis speed is increased.
FIG. 4 schematically shows a flow chart of a method of creating a first array according to an embodiment of the disclosure.
As shown in fig. 4, the method of creating the first array of this embodiment includes operations S401 to S402.
In operation S401, at least two placeholders for the first entity information are generated according to a first regular expression.
In operation S402, the message is divided into a first array according to the at least two placeholders, where the first array includes at least two segments of sub-messages.
In an alternative embodiment of the present disclosure, the first regular expression is (/ boundary ═. The message is divided into an array by identifying the placeholder M, the array is called as a first array, the sub-messages are members of the array, the first array can be used for processing each segment of sub-message in subsequent analysis processing, each segment of sub-message can be called more conveniently by using the array, and the sequence of the sub-messages in the multipart type message is represented.
In an embodiment of the present disclosure, in operation S202, a key name and a key value corresponding to at least two segments of sub-packets are determined, where the key name represents a data name of the sub-packet, and the key value represents a data value of the sub-packet, and each segment of the sub-packet includes a piece of header information and a piece of entity information, which are respectively referred to as second header information and second entity information, through parsing a packet structure. The method and the device for extracting the key value of the data structure of the JSON object have the advantages that the key name is determined according to the second head information of the sub-message, the key value is determined according to the second entity information of the sub-message, main data characteristics including the data name and the data value of the sub-message are extracted, and the JSON object of the data structure is conveniently represented.
Fig. 5 schematically shows a flowchart of a method for determining a key name and a key value according to an embodiment of the present disclosure.
As shown in fig. 5, the method of determining a key name and a key value of this embodiment includes operations S501 to S504.
In operation S501, the sub-packet is divided into second header information and second entity information according to a second delimiter in the sub-packet.
In operation S502, a second regular expression is obtained according to the second header information.
In operation S503, the second header information is processed using the second regular expression, resulting in a key name.
In operation S504, the second entity information is divided into a second array by using the row divider, and a first bit of the second array is the key value.
The sub-packet of the present disclosure also contains header information and entity information, and is divided into two elements, referred to as second header information and second entity information, respectively, by a second delimiter, such as a line break. And obtaining a second regular expression according to the second header information, for example, obtaining the second regular expression (/. a. times. name. "([. times.") $ /) according to the name field in the second header information, and processing the second header information by using the second regular expression to obtain the key name. And partitioning the second entity information into a second array by using the row partitioning character, wherein the second array can be a child array, and the first bit of the second array is the key value, namely the key value is child array [0 ].
In another embodiment of the present disclosure, in operation S203, generating a JSON object of a multipart type packet according to a key name and a key value includes: creating an empty object; and recording the key names corresponding to the at least two segments of sub-messages in the empty object, and respectively assigning the key values corresponding to the at least two segments of sub-messages to the key names corresponding to the at least two segments of sub-messages to generate the JSON object of the multipart type message. The JSON object is in the format { key1: value1, key2: value 2. For example, if a multipart type message includes 2 segments of sub-messages, which are respectively a sub-message 1 and a sub-message 2, where a sub-message l has a key name 1 and a key value1, and a sub-message 2 has a key name 2 and a key value2, then assigning the key values corresponding to the at least two segments of sub-messages to the key names corresponding to the at least two segments of sub-messages respectively: the generated JSON object may be expressed as { key name 1: key value1, key name 2: and 2, a JSON object table shows a data structure of the multipart type message, and the message can be directly used as an object in JavaScript for processing and calling, so that more convenient processing and calling are realized, and the processing and browsing of data are facilitated.
In another embodiment of the present disclosure, operation S503 is divided into two cases, including: detecting the type of the multipart type message; if the message of the multipart type is of the multipart/form-data type, constructing a second regular expression according to the name field in the second header information; and if the message of the multipart type is of the multipart/bytes type, constructing a second regular expression according to the bytes field in the second header information. The multipart/form-data type message can directly obtain a second regular expression according to the name field, and a key name representing the data name is obtained through the second regular expression. The multipart/bytes type message has no name field to represent the relevant information of each sub-message part, and can be used as a key name through the bytes field under the Content-Range field to generate a second regular expression of the multipart/bytes type message.
Fig. 6 schematically shows a flow chart of a message preprocessing method according to an embodiment of the present disclosure.
As shown in fig. 6, the message parsing method of this embodiment further includes a message preprocessing method, which includes operations S601 to S603.
In operation S601, an HTTP request message is received.
In operation S602, a multipart type message is screened out according to header information of the HTTP request message.
In operation S603, it is detected whether the first entity information of the packet is a character type, and if the entity information is not the character type, the first entity information is converted into the character type.
In the disclosure, it is determined whether a Content-Type field in header information of the HTTP request message is a multipart/form-data (or multipart/bytes) field, and the multipart Type message is screened out, if so, the processing is continued, otherwise, the flow is directly ended. And judging whether the first entity information of the message is of a character type, if so, continuing to execute the message analysis method, otherwise, converting the first entity information of the message into the character type for continuous processing, so as to be beneficial to follow-up matching by using a regular expression.
In a specific embodiment of the present invention, the message parsing method is used for processing a multipart/form-data type message:
S1, a first regular expression (/ boundary ═ (. (according to the array after the boundary string segmentation, the head element and the tail element are both empty strings, and N sub-messages are array members from 1 to N)
S2, circularly processing the first array A to obtain the key name and the key value of each item, and generating a JSON object, wherein the method comprises the following steps:
s21, setting k to 1; an empty object partsByName { } is defined.
S22, judging whether k is less than N, if yes, executing S23, otherwise executing S3.
S23, dividing the kth item A [ k ] in the first array A into an array of subparts (including two items, namely two members of second head information subparts [0] and second entity information subparts [1 ]) by using the second separator. The second header information, subparts [0], is partitioned into array headers of length H with a line change delimiter.
S24, processing the array headers circularly. (the first element of the array is a linefeed, no processing is required, and the loop starts with the first element), including:
s241, setting j to 1; an empty object headerFields is defined { }.
And S242, judging whether j is smaller than H, if so, executing S243, otherwise, executing S25.
S243, analyze headers [ j ], assign headfields [ j ], name ═ header [ j ]. match (/ { lambda. } name } 1] using the second regular expression (/ { lambda. } name } { ([ "] [ $ }).
And S244, judging whether the header fields, name is not null, if so, executing S245, otherwise, executing S246.
S245, fieldName assigned a header fields.
S246, the value of j is increased by 1, and then S542 is executed.
S25, dividing the second entity information subparts [1] into childArray arrays by using the division separators. Assigning a key name to the key value, partsByName [ fieldName ] ═ childArray [0 ];
s26, increasing the value of k by 1, and then executing S22.
And S3, outputting a JSON object partSByName.
Based on the message analysis method, the disclosure also provides a message analysis device. The apparatus will be described in detail below with reference to fig. 7.
Fig. 7 schematically shows a block diagram of a message parsing apparatus according to an embodiment of the present disclosure.
As shown in fig. 7, the message parsing apparatus 700 of this embodiment includes a segmentation module 701, a key name and key value module 702, and an object module 703.
The partitioning module 701 is configured to partition the first entity information of the multipart type packet into at least two segments of sub packets according to the first partition symbol in the first header information of the multipart type packet. In an embodiment, the dividing module 701 may be configured to perform the operation S201 described above, which is not described herein again.
The key name key assignment module 702 is configured to determine a key name and a key assignment corresponding to at least two segments of sub-packets. In an embodiment, the key name key module 702 may be configured to perform the operation S202 described above, which is not described herein again.
The object module 703 is configured to generate a JSON object of the multipart type packet according to the key name and the key value. In an embodiment, the object module 703 may be configured to perform the operation S203 described above, which is not described herein again.
According to the embodiment of the present disclosure, any multiple modules of the splitting module 701, the key name key value module 702 and the object module 703 may be combined into one module to be implemented, or any one of the modules may be split into multiple modules. Alternatively, at least part of the functionality of one or more of these modules may be combined with at least part of the functionality of the other modules and implemented in one module. According to an embodiment of the present disclosure, at least one of the segmentation module 701, the key name key-value module 702, and the object module 703 may be implemented at least in part as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented in hardware or firmware in any other reasonable manner of integrating or packaging a circuit, or in any one of or a suitable combination of software, hardware, and firmware. Alternatively, at least one of the segmentation module 701, the key name key module 702 and the object module 703 may be at least partially implemented as a computer program module, which when executed, may perform a corresponding function.
Fig. 8 schematically illustrates a block diagram of an electronic device adapted to implement a message parsing method according to an embodiment of the present disclosure.
As shown in fig. 8, an electronic device 800 according to an embodiment of the present disclosure includes a processor 801 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)802 or a program loaded from a storage section 808 into a Random Access Memory (RAM) 803. The processor 801 may include, for example, a general purpose microprocessor (e.g., CPU), an instruction set processor and/or associated chipset, and/or a special purpose microprocessor (e.g., Application Specific Integrated Circuit (ASIC)), among others. The processor 801 may also include onboard memory for caching purposes. The processor 801 may include a single processing unit or multiple processing units for performing different actions of the method flows according to embodiments of the present disclosure.
In the RAM 803, various programs and data necessary for the operation of the electronic apparatus 800 are stored. The processor 801, the ROM 802, and the RAM 803 are connected to each other by a bus 804. The processor 801 performs various operations of the method flows according to the embodiments of the present disclosure by executing programs in the ROM 802 and/or RAM 803. Note that the programs may also be stored in one or more memories other than the ROM 802 and RAM 803. The processor 801 may also perform various operations of method flows according to embodiments of the present disclosure by executing programs stored in the one or more memories.
The present disclosure also provides a computer-readable storage medium, which may be contained in the apparatus/device/system described in the above embodiments; or may exist separately and not be assembled into the device/apparatus/system. The computer-readable storage medium carries one or more programs which, when executed, implement the method according to an embodiment of the disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example but is not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, a computer-readable storage medium may include one or more memories other than the ROM 802 and/or RAM 803 and/or ROM 802 and RAM 803 described above.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the method illustrated by the flow chart. When the computer program product runs in a computer system, the program code is used for causing the computer system to realize the message parsing method provided by the embodiment of the disclosure.
The computer program performs the above-described functions defined in the system/apparatus of the embodiments of the present disclosure when executed by the processor 801. The above described systems, devices, modules, units, etc. may be implemented by computer program modules according to embodiments of the present disclosure.
In one embodiment, the computer program may be hosted on a tangible storage medium such as an optical storage device, a magnetic storage device, and the like. In another embodiment, the computer program may also be transmitted in the form of a signal on a network medium, distributed, downloaded and installed via communication section 809, and/or installed from removable media 811. The computer program containing program code may be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 809 and/or installed from the removable medium 811. The computer program, when executed by the processor 801, performs the above-described functions defined in the system of the embodiments of the present disclosure. The systems, devices, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
In accordance with embodiments of the present disclosure, program code for executing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, these computer programs may be implemented using high level procedural and/or object oriented programming languages, and/or assembly/machine languages. The programming language includes, but is not limited to, programming languages such as Java, C + +, python, the "C" language, or the like. The program code may execute entirely on the user's computing device, partly on the user's device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind 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).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
It will be appreciated by a person skilled in the art that various combinations or/and combinations of features recited in the various embodiments of the disclosure and/or in the claims may be made, even if such combinations or combinations are not explicitly recited in the disclosure. In particular, various combinations and/or combinations of the features recited in the various embodiments and/or claims of the present disclosure may be made without departing from the spirit or teaching of the present disclosure. All such combinations and/or associations are within the scope of the present disclosure.
The embodiments of the present disclosure are described above. However, these examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described separately above, this does not mean that the measures in the embodiments cannot be used in advantageous combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be devised by those skilled in the art without departing from the scope of the present disclosure, and such alternatives and modifications are intended to be within the scope of the present disclosure.
Claims (12)
1. A message parsing method includes:
according to a first divider in first header information of a multipart type message, dividing first entity information of the multipart type message into at least two sections of sub-messages;
Determining key names and key values respectively corresponding to the at least two sections of sub-messages;
and generating a JSON object of the multipart type message according to the key name and the key value.
2. The method according to claim 1, wherein the determining the key name and the key value respectively corresponding to the at least two segments of sub-packets comprises:
and determining the key name according to the second head information of the sub-message, and determining the key value according to the second entity information of the sub-message.
3. The method of claim 1, wherein the splitting the first entity information of the multipart type packet into at least two sub-packets according to the first splitter in the first header information of the multipart type packet comprises:
constructing a first regular expression according to the first separator, wherein the first separator at least comprises a boundary field;
and dividing the first entity information into at least two segments of sub-messages according to a first regular expression.
4. The method of claim 3, wherein the segmenting the first entity information into at least two segments of sub-packets according to the first regular expression comprises:
generating at least two placeholders for the first entity information according to the first regular expression;
And dividing the message into a first array according to the at least two placeholders, wherein the first array comprises at least two sections of sub-messages.
5. The method of claim 2, wherein the determining the key name according to the second header information of the sub-packet and the determining the key value according to the second entity information of the sub-packet comprise:
dividing the sub-message into the second header information and second entity information according to a second separator in the sub-message;
obtaining a second regular expression according to the second head information;
processing the second head information by using the second regular expression to obtain the key name;
and dividing the second entity information into a second array by using a row partitioning character, wherein the first bit of the second array is the key value.
6. The method according to claim 1, wherein the generating a JSON object of the multipart type packet according to the key name and the key value comprises:
creating an empty object;
and recording the key names corresponding to the at least two segments of sub-messages in the empty object, and respectively assigning the key values corresponding to the at least two segments of sub-messages to the key names corresponding to the at least two segments of sub-messages to generate the JSON object of the multipart type message.
7. The method of claim 5, wherein said obtaining a second regular expression from the second header information comprises:
detecting the type of the multipart type message;
if the message of the multipart type is of the multipart/form-data type, constructing a second regular expression according to the name field in the second header information;
and if the message of the multipart type is of the multipart/bytes type, constructing a second regular expression according to the bytes field in the second header information.
8. The method of claim 1, wherein the message parsing method further comprises:
receiving an HTTP request message;
screening the multipart type message according to the header information of the HTTP request message;
and detecting whether the first entity information of the message is of a character type, and if not, converting the first entity information into the character type.
9. A message parsing apparatus, comprising:
the device comprises a partitioning module, a first sending module and a second sending module, wherein the partitioning module is used for partitioning first entity information of a multipart type message into at least two sections of sub-messages according to a first partitioning symbol in first header information of the multipart type message;
The key name key value module is used for determining the key names and key values respectively corresponding to the at least two sections of sub-messages; and
and the object module is used for generating a JSON object of the multipart type message according to the key name and the key value.
10. An electronic device, comprising:
one or more processors;
a storage device to store one or more programs,
wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method of any of claims 1-8.
11. A computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to perform the method of any one of claims 1 to 8.
12. A computer program product comprising a computer program which, when executed by a processor, implements a method according to any one of claims 1 to 8.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210288882.0A CN114760374B (en) | 2022-03-22 | 2022-03-22 | Message parsing method and device, electronic equipment and medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210288882.0A CN114760374B (en) | 2022-03-22 | 2022-03-22 | Message parsing method and device, electronic equipment and medium |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN114760374A true CN114760374A (en) | 2022-07-15 |
| CN114760374B CN114760374B (en) | 2023-12-05 |
Family
ID=82327098
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202210288882.0A Active CN114760374B (en) | 2022-03-22 | 2022-03-22 | Message parsing method and device, electronic equipment and medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN114760374B (en) |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20140059140A1 (en) * | 2012-08-21 | 2014-02-27 | International Business Machines Corporation | Formatting rich text data into a json array |
| CN107026821A (en) * | 2016-02-01 | 2017-08-08 | 阿里巴巴集团控股有限公司 | The processing method and processing device of message |
| CN113395292A (en) * | 2021-07-07 | 2021-09-14 | 中国工商银行股份有限公司 | Message processing method and device, electronic equipment and storage medium |
| CN114124918A (en) * | 2021-11-25 | 2022-03-01 | 中国银行股份有限公司 | Message parsing method and device |
-
2022
- 2022-03-22 CN CN202210288882.0A patent/CN114760374B/en active Active
Patent Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20140059140A1 (en) * | 2012-08-21 | 2014-02-27 | International Business Machines Corporation | Formatting rich text data into a json array |
| CN107026821A (en) * | 2016-02-01 | 2017-08-08 | 阿里巴巴集团控股有限公司 | The processing method and processing device of message |
| CN113395292A (en) * | 2021-07-07 | 2021-09-14 | 中国工商银行股份有限公司 | Message processing method and device, electronic equipment and storage medium |
| CN114124918A (en) * | 2021-11-25 | 2022-03-01 | 中国银行股份有限公司 | Message parsing method and device |
Also Published As
| Publication number | Publication date |
|---|---|
| CN114760374B (en) | 2023-12-05 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US9779069B2 (en) | Model traversing based compressed serialization of user interaction data and communication from a client-side application | |
| US10284671B2 (en) | Dynamic bundling of web components for asynchronous delivery | |
| US20180246863A1 (en) | Dynamic streaming content | |
| CN110120917A (en) | Method for routing and device based on content | |
| US9680897B2 (en) | Throttled scanning for optimized compression of network communicated data | |
| US11934287B2 (en) | Method, electronic device and computer program product for processing data | |
| CN113382083B (en) | Webpage screenshot method and device | |
| US10339572B2 (en) | Tracking user interaction with a stream of content | |
| CN110753050B (en) | Method and device for generating protocol document, computer storage medium and electronic equipment | |
| CN115080154B (en) | Page display method, device, storage medium and electronic device | |
| EP3872630B1 (en) | Request processing method and apparatus, electronic device, and computer storage medium | |
| US20190325485A1 (en) | Tracking user interaction with a stream of content | |
| CN114125067A (en) | Grayscale publishing method, front-end server and configuration server with front-end and back-end separation | |
| CN111427899A (en) | Method, device, equipment and computer readable medium for storing file | |
| CN113553123A (en) | Data processing method and device, electronic equipment and storage medium | |
| US12229176B1 (en) | Software utility toolbox for client devices | |
| CN114760374B (en) | Message parsing method and device, electronic equipment and medium | |
| CN116781586A (en) | gRPC flow analysis method, device, equipment and medium | |
| CN116561013A (en) | Test method, device, electronic equipment and medium based on target service framework | |
| CN113392623B (en) | Service data object generation method, generation device, electronic device and storage medium | |
| CN116860172A (en) | Request processing method, data acquisition device and electronic equipment | |
| WO2019122011A1 (en) | Computer system and method for extracting dynamic content from websites | |
| CN111949472B (en) | A method and device for recording application logs | |
| CN117390312A (en) | Page rendering method, device, equipment, storage medium and program product | |
| CN113656618A (en) | Picture synchronization method and device, electronic equipment and readable storage medium |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |