Data processing method and related device
By including data type information in the serialized data and parsing it during deserialization, the data recovery problem after business interruption is solved, and the correct recovery of data types and the normal operation of business processes are achieved.
Patent Information
- Application Number
- CN202311836998.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-28
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2043-12-28
AI Technical Summary
The prior art cannot effectively restore JSON format data after the service interruption of electronic devices, resulting in the inability to recover the service normally and affecting the user experience.
By including the data type information of the target data in the serialized data and parsing the information during the deserialization process, the real data type of the target data is restored, so that it can be used correctly in the original business environment.
It realizes that when business recovery, the data type of the target data is correctly restored, ensuring that the data is available in the original business environment, and restoring the normal operation of the business process.
Smart Images

Figure CN117874303B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal technology, and in particular to a data processing method and related devices. Background Art
[0002] JSON is a lightweight data exchange format that's easy for humans to read and write, as well as for machines to parse and generate. In programming practice, using JSON as a data storage format for serialization and deserialization is widely used. In some examples, JSON serialization tools can be used to store class objects in high-level languages (such as C++) as bytes to disk, in a database, or for transmission. JSON deserialization tools can also be used to restore serialized byte objects to class objects.
[0003] In some implementations, when a service is interrupted on an electronic device, the device serializes the data related to that service into JSON format and stores it. When the service is restored, the JSON data is deserialized and applied to the original service process to restore the service. However, there are currently cases where service cannot be restored after an interruption, affecting the user experience. Summary of the Invention
[0004] The embodiments of the present application provide a data processing method and related devices, which can ensure that the serialized data obtained by serializing the target data includes the data type information of the target data, and the data type information can be parsed during the deserialization process, which is conducive to restoring the target data to the correct data type during the deserialization process, facilitating the use of the target data in the context of the original business environment, and facilitating the recovery of business processes implemented based on the target data.
[0005] In a first aspect, an embodiment of the present application proposes a data processing method, which is applied to an electronic device, and the method includes: obtaining target data; serializing the target data to obtain serialized data, wherein the serialized data includes data type information of the target data, and the data type information supports being parsed during deserialization.
[0006] It should be understood that the target data can be any object, such as a Bean entity object, a generic Map object, an Object object, or other custom objects, and this application does not limit this.
[0007] In an embodiment of the present application, the serialized data obtained after serializing the target data includes the data type information of the target data, and the data type information supports being parsed during the deserialization process and can be used to restore the true data type of the target data. In this way, no matter what data type the target data is, after serialization processing based on the data processing method provided by the present application, the true data type of the target data can be restored during the deserialization process, which is conducive to the use of the target data in the original context and to the recovery of business processes implemented based on the target data.
[0008] In combination with the first aspect, in some implementations of the first aspect, the serialized data includes a first key-value pair, the first key-value pair includes a first key and a first value, and the first key includes data type information of the first value.
[0009] In a possible implementation, the first key may only include data type information of the first value.
[0010] In combination with the first aspect, in some implementations of the first aspect, the first key includes a first part and a second part, the first part is used to identify the first key-value pair, and the second part includes data type information of the first value.
[0011] In a possible implementation, the first key may include the second key corresponding to the first value in the target data and data type information of the first value.
[0012] In an embodiment of the present application, the first key includes the data type information of the first value. In this way, during the deserialization process, the data type information of the first value is obtained by identifying the first key, and then the first value is parsed based on the data type information of the first value, which helps to restore the original data type of the first value.
[0013] In combination with the first aspect, in some implementations of the first aspect, a first separator is provided between the first part and the second part.
[0014] Optionally, the first separator can be any character that can distinguish the first part from the second part, such as “ / ” or “:”, and this application does not limit this.
[0015] In combination with the first aspect, in certain implementations of the first aspect, the first value is an array, the second part also includes first information for indicating that the first value is an array, and the data type information of the first value includes data type information of the elements in the array.
[0016] Optionally, the first information may be used to indicate that the first value is a tuple, a set, a dictionary, or a list, and the data type information of the element may be an integer, a floating point, or a Boolean, but this application does not limit this.
[0017] In combination with the first aspect, in certain implementations of the first aspect, a second separator is further included between the first information and the data type information of the data element.
[0018] Optionally, the second separator can be, for example, “ / ”, “:” or any other character that can distinguish the first information from the data type information of the data element. The first separator and the second separator can be the same or different, and this application does not limit this.
[0019] In combination with the first aspect, in certain implementations of the first aspect, the target data includes a second key-value pair, the second key-value pair includes a second key and a first value; the serialization processing of the target data to obtain serialized data includes: determining the data type information of the first value; using the second key as the first part of the first key and the data type information of the first value as the second part of the first key to obtain a first key-value pair including the first key and the first value; converting the first key-value pair into a serialized format to obtain serialized data.
[0020] It should be understood that through the method provided in the embodiment of the present application, the second key-value pair included in the target data can be recombined into a first key-value pair, and the first key-value pair can be converted into a serialized format, the first key in the first key-value pair includes a first part and a second part, the first part may include the second key, and the second part may include data type information of the first value.
[0021] It should also be understood that the second key-value pair can generally refer to any key-value pair in the target data.
[0022] In an embodiment of the present application, by traversing all key-value pairs in the target data, new keys are assembled with the keys corresponding to the values according to the real data types of the values in different key-value pairs. For example, the second key in the second key-value pair is assembled with the data type information of the first value to obtain the first key, and the first key-value pair containing the first key and the first value is format-converted to obtain serialized data including the first key-value pair, so that the serialized data can contain the real data type of the value in each key-value pair, which is conducive to restoring the original data type through the deserialization process.
[0023] In combination with the first aspect, in certain implementations of the first aspect, the electronic device includes a target module, and obtaining the target data includes: when the business of the target module is interrupted, the target module obtains the target data; after serializing the target data to obtain the serialized data, it also includes: storing the serialized data.
[0024] Optionally, the target module can be an intent registration module, intent trigger module, slot analysis module, intent decision module and intent notification module in the electronic device. The service of the target module can be a smart film service or any other feasible service. This application does not specifically limit the target module and the service type of the target module.
[0025] Optionally, the serialized data may be stored in a database (DB), a file system, or a cloud server in the form of a string, which is not limited in this application.
[0026] In combination with the first aspect, in some implementations of the first aspect, the method further includes: acquiring the serialized data; extracting the data type information included in the serialized data; and parsing the serialized data based on the data type information to obtain the target data.
[0027] In an embodiment of the present application, the data type information of the target data contained in the serialized data is parsed during the deserialization process, and the values in the serialized data are parsed into their true data types based on the data type information, so that the serialized data can be restored to the original target data and can be used in the context of the original business.
[0028] In combination with the first aspect, in some implementations of the first aspect, obtaining the serialized data includes: when the service of the target module is restored, the target module obtains the serialized data.
[0029] In combination with the first aspect, in certain implementations of the first aspect, the serialized data includes a first key-value pair, and extracting the data type information included in the serialized data includes: extracting the data type information of the first value included in the first key in the first key-value pair.
[0030] In combination with the first aspect, in certain implementations of the first aspect, parsing the serialized data based on the data type information to obtain the target data includes: parsing the first value based on the data type information of the first value; combining the second key in the first key with the first value to obtain the target data containing a second key-value pair.
[0031] In combination with the first aspect, in some implementations of the first aspect, the data type information includes one or more of the following: integer type, floating point type, string type, list type, tuple type, dictionary type, set type, Boolean type, or custom type.
[0032] In a second aspect, an embodiment of the present application provides an electronic device, comprising an acquisition unit and a processing unit, wherein the acquisition unit is used to: acquire target data; the processing unit is used to: serialize the target data to obtain serialized data, wherein the serialized data includes data type information of the target data, and the data type information supports being parsed during deserialization.
[0033] Optionally, the acquisition unit and the processing unit can be integrated in the same target module. The target module can be the intention registration module, intention trigger module, slot analysis module, intention decision module and intention notification module in the electronic device. The business of the target module can be smart film-forming business or any other feasible business. This application does not make any specific limitations on the target module and the business type of the target module.
[0034] Optionally, the serialized data includes a first key-value pair, the first key-value pair includes a first key and a first value, and the first key includes data type information of the first value.
[0035] Optionally, the first key includes a first part and a second part, the first part is used to identify the first key-value pair, and the second part includes data type information of the first value.
[0036] Optionally, there is a first separator between the first part and the second part.
[0037] Optionally, the first value is an array, and the second part further includes first information for indicating that the first value is an array, and the data type information of the first value includes data type information of elements in the array.
[0038] Optionally, a second separator is further included between the first information and the data type information of the data element.
[0039] Optionally, the target data includes a second key-value pair, and the second key-value pair includes a second key and a first value;
[0040] Optionally, the processing unit is also used to: determine the data type information of the first value; use the second key as the first part of the first key and the data type information of the first value as the second part of the first key to obtain a first key-value pair including the first key and the first value; and convert the first key-value pair into a serialized format to obtain serialized data.
[0041] Optionally, the processing unit is further configured to: when the service of the target module is interrupted, the target module acquires the target data; and store the serialized data.
[0042] Optionally, the acquisition unit is further used to: acquire the serialized data; extract the data type information included in the serialized data; and the processing unit is further used to: parse the serialized data based on the data type information to obtain the target data.
[0043] Optionally, the acquisition unit is further configured to: acquire the serialized data when the service is restored.
[0044] Optionally, the serialized data includes a first key-value pair, and the extracting of the data type information included in the serialized data, the processing unit is further configured to extract the data type information of the first value included in the first key in the first key-value pair.
[0045] Optionally, the processing unit is further configured to: parse the first value based on data type information of the first value; and combine the second key in the first key with the first value to obtain the target data including a second key-value pair.
[0046] Optionally, the data type information includes one or more of the following: integer type, floating point type, string type, list type, tuple type, dictionary type, set type, Boolean type or custom type.
[0047] In a third aspect, an embodiment of the present application provides an electronic device. In one possible implementation, the electronic device may be a terminal device, which may also be referred to as a terminal, user equipment (UE), mobile station (MS), mobile terminal (MT), etc. The terminal device may be a mobile phone, a smart TV, a wearable device, a tablet computer (Pad), a computer with wireless transceiver functions, a virtual reality (VR) terminal device, an augmented reality (AR) terminal device, a wireless terminal in industrial control, a wireless terminal in self-driving, a wireless terminal in remote medical surgery, a wireless terminal in a smart grid, a wireless terminal in transportation safety, a wireless terminal in a smart city, a wireless terminal in a smart home, etc.
[0048] The electronic device includes: a processor and a memory; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, so that the terminal device executes the method of the first aspect.
[0049] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the method of the first aspect.
[0050] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is run, it enables the computer to execute the method of the first aspect.
[0051] In a sixth aspect, an embodiment of the present application provides a chip, the chip including a processor, the processor being used to call a computer program in a memory to execute the method described in the first aspect.
[0052] It should be understood that the second to fifth aspects of the present application correspond to the technical solutions of the first aspect of the present application, and the beneficial effects achieved by each aspect and the corresponding feasible implementation methods are similar and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 A schematic diagram of an electronic device interface provided in an embodiment of the present application;
[0054] Figure 2 An example diagram of a business framework provided in an embodiment of the present application;
[0055] Figure 3 A schematic flow chart of a data processing method provided in an embodiment of the present application;
[0056] Figure 4 A schematic flow chart of a serialization method provided in an embodiment of the present application;
[0057] Figure 5 A schematic flow chart of a deserialization method provided in an embodiment of the present application;
[0058] Figure 6 A schematic flow chart of another data processing method provided in an embodiment of the present application;
[0059] Figure 7 A schematic diagram of the structure of a chip provided in an embodiment of the present application. DETAILED DESCRIPTION
[0060] To facilitate a clear description of the technical solutions of the embodiments of the present application, some of the terms and technologies involved in the embodiments of the present application are briefly introduced below:
[0061] 1. Serialization: Serialization is the process of converting an object's state information into a form that can be stored or transmitted. During serialization, the object writes its current state to a temporary or persistent storage area, saving the state information as a string. After serialization, the object can be recreated by deserialization.
[0062] 2. Deserialization: Deserialization is to convert the serialized string into an object.
[0063] 3. Other terms
[0064] In the embodiments of this application, terms such as "first" and "second" are used to distinguish between identical or similar items with substantially the same functions and effects. For example, the terms "first chip" and "second chip" are used solely to distinguish between different chips and do not define their order. Those skilled in the art will understand that terms such as "first" and "second" do not define the quantity or execution order, and do not necessarily define differences.
[0065] It should be noted that in the embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described in this application as "exemplary" or "for example" should not be construed as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0066] In the embodiments of the present application, "at least one" refers to one or more, and "more" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: the existence of A alone, the existence of A and B at the same time, and the existence of B alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, a--c, bc, or abc, where a, b, c can be single or multiple.
[0067] 4. Electronic devices
[0068] The electronic devices of the embodiments of the present application may include handheld devices, vehicle-mounted devices, etc. with smart film-making functions. For example, some electronic devices include: mobile phones, tablet computers, PDAs, laptop computers, mobile internet devices (MIDs), wearable devices, virtual reality (VR) devices, augmented reality (AR) devices, wireless terminals in industrial control, wireless terminals in self-driving cars, wireless terminals in remote medical surgery, wireless terminals in smart grids, wireless terminals in transportation safety, wireless terminals in smart cities, wireless terminals in smart homes, cellular phones, cordless phones, session initiation protocol (SIP) phones, wireless local loop (WLL) stations, personal digital assistants (PDAs), handheld devices with wireless communication capabilities, computing devices or other processing devices connected to wireless modems, in-vehicle devices, wearable devices, terminal devices in 5G networks or future evolved public land mobile communication networks. The terminal equipment in the network (PLMN), etc., is not limited to this in the embodiments of the present application.
[0069] As an example and not a limitation, in the embodiments of the present application, the electronic device may also be a wearable device. Wearable devices may also be referred to as wearable smart devices, which are a general term for wearable devices that are intelligently designed and developed using wearable technology for daily wear, such as glasses, gloves, watches, clothing, and shoes. A wearable device is a portable device that is worn directly on the body or integrated into the user's clothes or accessories. Wearable devices are not only hardware devices, but also achieve powerful functions through software support, data interaction, and cloud interaction. Broadly speaking, wearable smart devices include those that are fully functional, large in size, and can achieve complete or partial functions without relying on smartphones, such as smart watches or smart glasses, as well as those that only focus on a certain type of application function and need to be used in conjunction with other devices such as smartphones, such as various smart bracelets and smart jewelry for vital sign monitoring.
[0070] In addition, in the embodiments of the present application, the electronic device can also be a terminal device in the Internet of Things (IoT) system. IoT is an important part of the future development of information technology. Its main technical feature is to connect objects to the network through communication technology, thereby realizing an intelligent network of human-machine interconnection and object-to-object interconnection.
[0071] The electronic devices in the embodiments of the present application may also be referred to as: terminal equipment, user equipment (UE), mobile station (MS), mobile terminal (MT), access terminal, user unit, user station, mobile station, mobile station, remote station, remote terminal, mobile device, user terminal, terminal, wireless communication equipment, user agent or user device, etc.
[0072] In the embodiments of the present application, the electronic device or each network device includes a hardware layer, an operating system layer running on the hardware layer, and an application layer running on the operating system layer. The hardware layer includes hardware such as a central processing unit (CPU), a memory management unit (MMU), and memory (also known as main memory). The operating system can be any one or more computer operating systems that implement business processing through processes, such as a Linux operating system, a Unix operating system, an Android operating system, an iOS operating system, or a Windows operating system. The application layer includes applications such as browsers, address books, word processing software, and instant messaging software.
[0073] In one possible implementation, an electronic device has a smart video-making function. This can be understood as the process by which the electronic device can intelligently detect and filter images and videos in a gallery based on user preferences and key moments, automatically matching them with music and subtitles to generate a short video, and then push it to the user at the appropriate time.
[0074] In one example, a user can Figure 1 The process shown starts the smart filming service. Users can enter the settings application and click "YOYO Suggestions" to enter the following Figure 1 In the YOYO suggestion interface shown in a, click "Smart Gallery" in the life service list to enter the following Figure 1 In the smart gallery service management interface shown in b, click the buttons corresponding to the smart gallery and smart photo editing in the interface to enable them. Then, the user can use the smart photo editing function. It should be understood that the activation process of the smart photo editing service may include more than Figure 1The interface shown may include more or fewer interfaces or buttons, and this application does not limit this.
[0075] In another example, the electronic device has a voice assistant and has turned on it. The user can input voice commands to the electronic device to turn on the smart film-making function. This application does not specifically limit the method of turning on the smart film-making function.
[0076] It should be understood that after the smart video function is turned on, the electronic device can intelligently detect and filter pictures and videos in the gallery according to the user's preferences and key nodes, automatically match music and subtitles to generate a short video, and push it to remind the user to view it at the appropriate time. Optionally, the video clip can be pushed to the desktop, the negative one screen, or other applications, which is not limited by this application.
[0077] In one possible implementation, the smart filming service can be based on Figure 2 The intent engine business framework is shown. Figure 2 As shown in the figure, the framework for implementing services based on the intent engine can include a business layer, an interface layer, an intent engine layer, and an intent recognition layer. The business layer includes scenarios or other plug-ins; the interface layer is used to provide open interfaces, through which interactions such as intent subscription and unsubscription can be performed; the intent engine layer is used to implement the process orchestration of intents. After intent registration (various fence registrations) and intent fence triggering, it executes the intent triggering, slot resolution, intent decision-making, intent notification and other processes to realize smart segmentation services; the intent recognition layer is used to register intent fences and, after the intent fence is triggered, notify the graph engine layer to execute each node according to the orchestrated process.
[0078] In some implementations, the user registers the intent to the intent registration module of the intent engine layer by calling the open interface of the interface layer through the business layer. The intent registration module transmits the intent registered by the user to the intent fence registration module to form an intent fence. When the intent fence identified by the intent recognition layer is triggered, the intent engine layer is notified of the intent fence trigger, so that the electronic device executes slot resolution, intent decision-making and intent notification processes based on the intent engine.
[0079] Optionally, Figure 2 The framework shown may be a framework corresponding to an artificial intelligence (AI) module in an electronic device. The AI module may be, for example, a YOYO suggestion. The above-mentioned smart filming service may be a YOYO suggestion based on the following example: Figure 2 The framework shown is implemented by interacting with applications such as gallery, calendar, music, etc., but this application is not limited to this.
[0080] For example, YOYO suggests combining the gallery and calendar to realize smart film formation as an example to illustrate the process of smart film formation. In the process of smart film formation, the process of intent registration can be understood as the process of YOYO suggesting to determine the timing of smart film formation and use the timing as the intent fence. For example, YOYO suggests that based on the interaction with the calendar, it determines that Valentine's Day is coming and decides to push a Valentine's Day-related video to the user on Valentine's Day. Therefore, the time of Valentine's Day is registered as an intent. When Valentine's Day comes, it can be considered that the intent is triggered. The intention engine layer of the electronic device performs slot analysis. Slot analysis can be understood as the process of YOYO suggesting to interact with the gallery and determine whether the video to be pushed is ready. When it is determined that the video to be pushed is ready, an intent decision is made. When the intent recognition layer identifies that the current scene meets the scene intent fence, an intent notification can be made, that is, YOYO suggests that it is ready to push the video generated by the gallery to the user. For example, the video can be pushed to the desktop, the negative one screen or other applications.
[0081] In one possible scenario, YOYO suggests that it is ready to push videos to users, but detects that the electronic device is in the screen-off state, which is not an effective time to push videos. Therefore, the smart film-making service is interrupted at the intention notification node. The intention notification module needs to store the context of the service so that it can read the context and restore the service when the service is restored. The context of the service is a class object, which needs to be converted into a serialized format for storage. In some examples, the electronic device can use the JSON serialization tool to store the context of the smart film-making service in the form of a string to the disk or database, and can also use the JSON deserialization tool to restore the serialized string to a class object after the service is restored.
[0082] In some implementations, the business context is a generic object. The so-called generic means that when the class is defined, the data types of the attributes and methods in the class are not specified. Instead, the corresponding data types are specified when the class object is created. This means that the data types of generic objects are not restricted and can include multiple data types. However, when generic objects are stored through existing serialization and restored through the existing deserialization process, since the existing serialization tool cannot recognize the classes of all class objects, the class objects it cannot recognize will be mapped to the class objects preset by the tool instead of the original class objects. For example, the existing serialization tool Gson will deserialize any json string into a Map object. If the original class object of the string is not a Map object, the correct class object data type cannot be restored through the Gson deserialization process, resulting in the deserialized class object being different from the original class object of the data and difficult to use in the original context.
[0083] In view of this, the present application provides a data processing method and related devices, which can ensure that the serialized data obtained by serializing the target data includes the data type information of the target data, and the data type information can be parsed during the deserialization process, which is conducive to recovering the data type information of the target data during the deserialization process, facilitating the use of the target data in the context of the original business environment, and facilitating the recovery of business processes.
[0084] It should be understood that the above-mentioned smart film-forming business can be interrupted and restored at any node in the business process such as intent registration, intent triggering, slot resolution, intent decision-making, intent notification, etc., and this application does not limit this.
[0085] It should also be understood that the above Figure 2 The business framework shown is not limited to the implementation of smart film-forming services, and the data processing method provided in the embodiment of the present application is not limited to execution in the case of interruption and recovery of smart film-forming services. It is applicable to any business that can be performed by electronic devices, and this application does not limit this.
[0086] Next, we will first introduce the process of electronic devices processing business-related data after the business process is interrupted and when the business process is restored. Figure 3 A flow chart of a data processing method 300 is shown as an example.
[0087] The method 300 includes the following steps:
[0088] S301. In case of service interruption, obtain the member quantity (field).
[0089] It should be understood that the member quantity (field) is a field in the description of the business data. Optionally, the business data can be defined by any object, such as a Bean entity object, a generic Map object, an Object object, or other custom objects, which is not limited in this application.
[0090] Optionally, the service may be a smart film service or any other service, which is not specifically limited in this application.
[0091] S302: Determine whether to convert the member quantity into JSON based on the annotation of the member quantity. If so, execute S303.
[0092] It should be understood that the data storage format can be JSON format or other formats, and this application does not make specific limitations on this.
[0093] In a possible implementation, the field may be identified in the form of an annotation to describe the format of storing the data. Optionally, when the electronic device recognizes that the annotation is JSON, S303 is executed.
[0094] S303: Convert the member quantity from the object to JSON.
[0095] For example, the member quantity may be converted from an object to JSON by referring to the subsequent method 400, which will not be described in detail here.
[0096] S304: Store the JSON in a database (DB) in a string format.
[0097] Optionally, the JSON structure can also be stored in a file system or a cloud server, etc., which is not limited in this application.
[0098] Optionally, when the service is restored, subsequent S305 to S308 are executed.
[0099] For example, if the service is a smart video creation service and the purpose of the service process is to push a Valentine's Day-related video to the user on Valentine's Day, the service may be interrupted in the following situations: the smart video creation process has been started, but the gallery has not yet prepared the video; the gallery has prepared the video, but Valentine's Day has not arrived; or Valentine's Day has arrived and the gallery has also prepared the video, but the electronic device is currently in the screen-off state. Correspondingly, if the service corresponding to any of the above situations is restored, the electronic device can execute S305-S308.
[0100] S305: Read data in a string format from the database.
[0101] S306: Determine whether the data is JSON. If so, execute S307.
[0102] It should be understood that business recovery means that the serialized data needs to be deserialized so that it can be used in the original context.
[0103] For example, after reading data from the database in String format, if the mapped field is of JSON type, the JSON is reverse-serialized into member quantities. At this time, it is necessary to know the original data type of the field, because the framework supports both Map structures and the most basic object type of Object.
[0104] S307: Convert the JSON into an object based on the original object type.
[0105] For example, the member quantity may be converted from an object to JSON with reference to the subsequent method 500, which will not be described in detail here.
[0106] S308. Obtain the original member quantity.
[0107] It should be understood that the data type of the original member quantity obtained is the same as that when the business is interrupted, that is, it can be understood that the original member quantity obtained in S308 is consistent with the member quantity obtained in S301. In this way, it can be identified in the original context when the business is restored, which is conducive to the normal operation of the business process.
[0108] Next, combine Figure 4 This section introduces the serialization process.
[0109] Figure 4 The following is a schematic flow chart of a serialization method 400 provided in an embodiment of the present application. The method 400 includes the following steps:
[0110] S401. Get the Map of the object to be serialized<String,Object> .
[0111] It should be understood that Map<String,Object> It is a data structure in Java that represents a mapping relationship, where the key is a string type and the value is an object type, meaning that Map<String,Object> The member quantity in the above method 400 can be understood as a Map<String,Object> The fields in .
[0112] S402: Traverse all key-value pairs in the object.
[0113] In one possible implementation, Map<String,Object> The data includes multiple key-value pairs, and the following S403 to S404 can be executed for the key and value in each key-value pair.
[0114] S403. Utilize the reflection mechanism to extract the real data type of the value.
[0115] S404: Assemble a new key, which includes the real data type of the original key and / or value. The key-value pair of the new key and value replaces the original key-value pair.
[0116] In one possible implementation, there are three ways to assemble a new key:
[0117] Method 1: When the actual data type of the value is string or Boolean, use the original key as the new key.
[0118] It should be understood that during the deserialization process, basic data types such as string type and Boolean type are easy to identify and do not require additional identification of their data types. Therefore, when the actual data type of the value is string type or Boolean type, the original key does not need to be processed, which helps to reduce the complexity of data processing in the subsequent deserialization process.
[0119] Method 2: When the actual data type of the value is a list type, tuple type, dictionary type, or set type, and the value contains multiple elements, obtain the data type of the value and the data type of the element. The new key includes the original key, the data type of the value, and the data type of the element.
[0120] For example, the first separator can be used to separate the data types of the original key and value, and the second separator can be used to separate the data type of the value and the data type of the element. The first separator can be " / " and the second separator can be ":", but this application does not limit this.
[0121] Method 3: When the actual data type of the value is an integer, floating-point type, or a custom type, the new key includes the actual data types of the original key and value.
[0122] Exemplarily, the data type of the original key and value can be separated by a first separator, and the first separator can be “ / ”, but this application does not limit this.
[0123] In a possible implementation, the custom type may be a custom class object, or may be further nested, which is not limited in this application.
[0124] S405. Determine whether the traversal is completed. If so, execute S406. If not, return to continue executing S402 to S405.
[0125] S406: Convert all new key and value pairs into JSON.
[0126] In an embodiment of the present application, when traversing all key-value pairs in the object to be serialized, new keys are assembled with the keys corresponding to the values according to the real data types of the values in different key-value pairs, so that the final JSON structure can contain the real data type of the value in each key-value pair, which is conducive to restoring the original data type of each member quantity in the object through the deserialization process.
[0127] The structure of the JSON data obtained after processing by the above method 400 is described below with reference to a specific example. The data structure may be as follows: Example 1:
[0128]
[0129]
[0130] In a possible implementation, value is an integer, floating-point data, or a custom data type.
[0131] For example, take the key-value pair "key_float / java.lang.Float":1.0 as an example, where the key of this key-value pair is "key_float / java.lang.Float", which includes two parts: key_float and java.lang.Float. Among them, key_float is used to identify the key-value pair. For example, key_float can be the key corresponding to 1.0 in the original business data, and java.lang.Float is used to indicate that the data type of 1.0 is a floating point type (Float).
[0132] Optionally, there is a first separator between key_float and java.lang.Float. The first separator can be, for example, “ / ”, “:”, etc., which is not limited in this application.
[0133] In another possible implementation, value is an array containing multiple elements. The new key corresponding to the value can be one of the following two examples:
[0134] In one example, multiple elements in value have the same data type.
[0135] For example, take the "key_list / java.uti1.Arraylist:java.lang.Integer":[1,2,3] in the above example as an example, where value is an array including the three elements 1, 2, and 3. In the new key corresponding to the value, java.uti1.Arraylist is used to indicate that value includes multiple elements and the multiple elements are in list form, and java.lang.Integer is used to indicate that the data type of the multiple elements included in value is integer (Integer).
[0136] In another example, the data types of multiple elements in value are not all the same.
[0137] For example, taking the JSON data including "key_list / java.uti1.Arraylist:java.lang.Integer:java.lang.Float:java.lang.Integer":[1,2.0,3] as an example, where value includes the three elements 1, 2.0, and 3, then in the new key corresponding to the value, java.uti1.Arraylist is used to indicate that value includes multiple elements and the multiple elements are in list form, java.lang.Integer is used to indicate that the data type of the first element in value is integer (Integer), java.lang.Float is used to indicate that the data type of the second element in value is floating-point type (Float), and java.lang.Integer is used to indicate that the data type of the third element in value is integer (Integer).
[0138] Optionally, when value is an array, value can be a tuple, set, dictionary or list type, and the elements in value can be integer, floating point or Boolean, but this application does not limit this.
[0139] In another possible implementation, value can be a nested class object.
[0140] Take the "key_map / java.uti1.HashMap":{"subkey_long / java.lang.Long":2,"subkey_int / Java.Jang.Integer":2} in the above example as an example, where the new key corresponding to the value is indicated by java.uti1.HashMap as a Map object, and the value{"subkey_long / java.lang.Long":2,"subkey_int / Java.Jang.Integer":2} includes the first sub-key-value pair "subkey_long / java.lang.Long ":2 and the second sub-key-value pair "subkey_int / Java.Jang.Integer":2, wherein the first sub-key-value pair includes the first sub-key subkey_long / java.lang.Long and the first sub-value 2, and the pattern of the first sub-key also conforms to the above description of the new key corresponding to the value, that is, the first sub-key indicates that the data type of the first sub-value 2 is a long integer (Long) through java.lang.Long; the second sub-key-value pair includes the second sub-key subkey_int / Java.Jang.Integer and the second sub-value 2, and the second sub-key indicates that the data type of the second sub-value 2 is an integer (Integer) through java.lang.Long.
[0141] Next, combine Figure 5 This section describes the deserialization process.
[0142] Figure 5 The following is a schematic flow chart of a deserialization method 500 provided in an embodiment of the present application. The method 500 shows the process of deserializing the JSON data obtained in the above method 400. The method 500 includes:
[0143] S501: Acquire JSON data and pre-process the JSON data into a JSON object.
[0144] It should be understood that the JSON data obtained from the database is in a string format. Exemplarily, the JSON string can be preprocessed into a JSON object before deserialization so that a deserialization tool can recognize the object.
[0145] S502: Traverse all key-value pairs in the JSON object.
[0146] It should be understood that the key in the JSON object is the new key obtained in the above method 400. In the process of traversing all key-value pairs in the JSON object, if the key does not contain a delimiter, then the key does not need to be parsed; if the key contains a delimiter, then the following S503 to S505 can be executed.
[0147] S503: Extract the real data type of the value included in the key, and parse the value corresponding to the key into its real data type.
[0148] The ways to parse the value according to its true data type include:
[0149] Method 1: If the key only contains the first delimiter, the data before the first delimiter is the original key, and the data after the first delimiter is the actual data type of the value.
[0150] Method 2: If the key contains a first separator and at least one second separator, then the value is an array containing multiple elements. The value before the first separator is the original key, the data type of the value (such as a set, list, dictionary, or tuple) is between the first separator and the first second separator after the first separator, and the data type of the element (integer, floating-point, or string) is between each second separator in the at least one second separator.
[0151] In one possible implementation, if the number of at least one second separator is one, the data types of multiple elements in value are the same; if the number of at least one second separator is multiple, the data types of multiple elements in value may not be all the same, and the number of at least one second separator may be equal to the number of elements.
[0152] S504: Restore the original key-value pair.
[0153] It should be understood that the data type of the value in the restored original key-value pair is its original, real data type, rather than the unified data type preset by the serialization tool.
[0154] S505: Determine whether the traversal is completed. If so, execute S506; if not, return to execute S502 to S505.
[0155] S506: Synthesize the object.
[0156] It should be understood that the format of serialized data is a string format, and the format of business data can be a generic Map object.
[0157] In an embodiment of the present application, the data type information contained in the JSON object is parsed during the deserialization process, and the values in the serialized data are parsed into their true data types based on the data type information, so that the JSON data can be converted into an object containing the correct data type and can be used in the context of the original business.
[0158] It should be understood that the order of execution of the above methods does not necessarily mean the order in which they are executed. The order in which the methods are executed should be determined by their functions and internal logic.
[0159] The data processing method of the embodiment of the present application is described in detail below through specific embodiments. The following embodiments can be combined with each other or implemented independently, and the same or similar concepts or processes may not be repeated in some embodiments.
[0160] Figure 6 A schematic flow chart of a data processing method 600 provided in an embodiment of the present application, which can be executed by an electronic device, can be based on Figure 2 The business framework shown implements the smart film-forming business or any other achievable business, and this application does not limit this.
[0161] The method 600 includes:
[0162] S601: Acquire target data.
[0163] S602: Serialize the target data to obtain serialized data. The serialized data includes data type information of the target data, and the data type information can be parsed during deserialization.
[0164] It should be understood that the target data may be the business data described in the above embodiment, and the business may be a smart film-making business, but this application does not limit this.
[0165] Optionally, the method for serializing the target data may refer to the above method 400 , and the target data may be an object to be serialized, which will not be described in detail here.
[0166] In an embodiment of the present application, the serialized data obtained after serializing the target data includes the data type information of the target data, and the data type information supports being parsed during the deserialization process and can be used to restore the true data type of the target data. In this way, no matter what data type the target data is, after serialization processing based on the data processing method provided by the present application, the true data type of the target data can be restored during the deserialization process.
[0167] As an optional embodiment, the electronic device includes a target module. An implementation of the above S601 includes: when a service of the target module is interrupted, the target module obtains target data; after the above S602, the method 600 further includes:
[0168] S603: Store serialized data.
[0169] Alternatively, the target module can be Figure 2 The intent registration module, intent trigger module, slot analysis module, intent decision module and intent notification module shown in the figure, the business of the target module can be a smart film business or any other feasible business. This application does not make any specific restrictions on the target module and the business type of the target module.
[0170] Optionally, the serialized data may be stored in a database (DB), a file system, or a cloud server in the form of a string, which is not limited in this application.
[0171] As an optional embodiment, the target data includes a second key-value pair, the second key-value pair includes a second key and a first value, and the target data is serialized in the above S602 to obtain serialized data, including: determining the data type information of the first value; using the second key as the first part of the first key and the data type information of the first value as the second part of the first key to obtain a first key-value pair including the first key and the first value; converting the first key-value pair into a serialized format to obtain serialized data.
[0172] It should be understood that the second key-value pair can generally refer to any key-value pair in the target data. For example, the second key in the second key-value pair can be the "original key" described in methods 400 and 500 above, and the first key in the first key-value pair can be the "new key" described in methods 400 and 500 above. The "original key" and the "new key" correspond to the same value. Optionally, the method for serializing the target data in the embodiment of the present application can refer to the above method 400 and will not be repeated here.
[0173] After the target data is serialized using the method provided in the embodiment of the present application, taking the serialized data including the first key-value pair as an example, the first key-value pair includes a first key and a first value. The structure of the first key can be implemented in the following two ways:
[0174] First implementation: The first key includes a first part and a second part, the first part is used to identify the first key-value pair, and the second part includes the data type information of the first value. For a specific example, refer to Example 1 above.
[0175] Optionally, a first separator is further provided between the first part and the second part. The first separator is used to separate the first part and the second part to facilitate identification by the electronic device. The first separator may be, for example, a character such as " / " or ":", which is not limited in this application.
[0176] In the case that the first value is an array, the second part further includes first information for indicating that the first value is an array, and the data type information of the first value includes data type information of elements in the array.
[0177] Optionally, a second separator is further included between the first information and the data type information of the data element. The second separator can be, for example, any character that can distinguish the first information from the data type information of the data element, such as " / " or ":". The first separator and the second separator can be the same or different, and this application does not limit this.
[0178] Second implementation: The first key only includes the data type information of the first value. That is, the first key can exclude the first part of the first implementation. This way, the true data type is stored during serialization, while reducing the complexity of subsequent parsing.
[0179] For example, if the target service is a smart video creation service and the purpose of the service process is to push a Valentine's Day-related video to the user on Valentine's Day, the service may be interrupted in the following situations: the smart video creation process has been started, but the gallery has not yet prepared the video; the gallery has prepared the video, but Valentine's Day has not arrived; or Valentine's Day has arrived and the gallery has also prepared the video, but the electronic device is currently in the screen-off state. Correspondingly, if the service corresponding to any of the above situations is restored, the electronic device can execute the following processes corresponding to S604 to S606.
[0180] As an optional embodiment, after the above S603, the method 600 further includes:
[0181] S604: Obtain serialized data.
[0182] Optionally, when the business of the target module is recovered, the target module obtains the serialized data.
[0183] S605: Extract data type information included in the serialized data.
[0184] In one possible implementation, the serialized data includes a first key-value pair, the first key-value pair including a first key and a first value. Extracting the data type information included in the serialized data may include extracting the data type information of the first value included in the first key in the first key-value pair. It should be understood that the first key-value pair may generally refer to any key-value pair in the serialized data.
[0185] S606: Parse the serialized data based on the data type information to obtain target data.
[0186] It should be understood that business recovery of the target module means that the serialized data needs to be deserialized so that it can be used in the original context.
[0187] Optionally, an implementation of the above S606 may be: parsing the first value based on the data type information of the first value; combining the second key in the first key with the first value to obtain target data containing the second key-value pair.
[0188] Optionally, the serialization processing of the target data after the service is interrupted and the deserialization processing of the serialized data after the service is restored can be implemented by the same target module, but this application does not limit this.
[0189] As an optional embodiment, the data type information of the first value includes one or more of the following: integer type, floating point type, string type, list type, tuple type, dictionary type, set type, Boolean type, or custom type.
[0190] It should also be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0191] The data processing method provided in the embodiment of the present application can be applied to electronic devices with communication functions. The specific device form of the electronic device can refer to the above related description and will not be repeated here.
[0192] It should be understood that in order to implement the above functions, the electronic device may include hardware structures and / or software modules that perform the corresponding functions. Those skilled in the art should easily realize that, in combination with the method steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0193] The embodiment of the present application can divide the functional modules of the device implementing the method according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. In actual implementation, there may be other division methods.
[0194] Figure 7 A schematic diagram of the structure of a chip provided in an embodiment of the present application: a chip 700 includes one or more (including two) processors 701 , a communication circuit 702 , a communication interface 703 , and a memory 704 .
[0195] In some embodiments, the memory 704 stores the following elements: executable modules or data structures, or a subset thereof, or an extended set thereof.
[0196] The method described in the above embodiment of the present application can be applied to the processor 701, or implemented by the processor 701. The processor 701 may be an integrated circuit chip with signal processing capabilities. During the implementation process, each step of the above method can be completed by an integrated logic circuit of the hardware in the processor 701 or an instruction in the form of software. The above-mentioned processor 701 can be a general-purpose processor (for example, a microprocessor or a conventional processor), a digital signal processor (digital signal processing, DSP), an application specific integrated circuit (application specific integrated circuit, ASIC), a field-programmable gate array (field-programmable gate array, FPGA) or other programmable logic devices, discrete gates, transistor logic devices or discrete hardware components. The processor 701 can implement or execute the methods, steps and logic block diagrams related to each processing disclosed in the embodiment of the present application.
[0197] The steps of the method disclosed in the embodiments of the present application can be directly implemented as being executed by a hardware decoding processor, or can be implemented by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art, such as a random access memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable read-only memory (EEPROM). The storage medium is located in the memory 704, and the processor 701 reads the information in the memory 704 and completes the steps of the above method in combination with its hardware.
[0198] The processor 701 , the memory 704 , and the communication interface 703 can communicate with each other via a communication line 702 .
[0199] In the above embodiment, the instructions stored in the memory for execution by the processor may be implemented in the form of a computer program product, wherein the computer program product may be pre-written in the memory or downloaded and installed in the memory in the form of software.
[0200] In the embodiment of the present application, the chip 700 may also be a chip system, such as a system on chip (SoC), which is not limited in the present application.
[0201] An embodiment of the present application provides an electronic device, comprising: a processor and a memory; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, so that the terminal device executes the above method.
[0202] The embodiments of the present application also provide a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the above method can be implemented. The methods described in the above embodiments can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. If implemented in software, the functions can be stored as one or more instructions or codes on a computer-readable medium or transmitted on a computer-readable medium. Computer-readable media can include computer storage media and communication media, and can also include any medium that can transfer a computer program from one place to another. The storage medium can be any target medium that can be accessed by a computer.
[0203] In one possible implementation, a computer-readable medium may include RAM, ROM, compact disc read-only memory (CD-ROM) or other optical disc storage, magnetic disk storage or other magnetic storage devices, or any other medium intended to carry or store the desired program code in the form of instructions or data structures and accessible by a computer. Moreover, any connection is appropriately referred to as a computer-readable medium. For example, if a coaxial cable, fiber optic cable, twisted pair, digital subscriber line (DSL) or wireless technology (such as infrared, radio and microwave) is used to transmit software from a website, server or other remote source, the coaxial cable, fiber optic cable, twisted pair, DSL or wireless technology such as infrared, radio and microwave are included in the definition of medium. Disk and optical disc as used herein include optical disc, laser disc, optical disc, digital versatile disc (DVD), floppy disk and Blu-ray disc, where disks generally reproduce data magnetically, while optical discs reproduce data optically using lasers. Combinations of the above should also be included within the scope of computer-readable media.
[0204] An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed, the computer executes the above method.
[0205] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable device to produce a machine, so that the instructions executed by the processing unit of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0206] The above specific implementation methods further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above are only specific implementation methods of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent replacements, improvements, etc. made on the basis of the technical solutions of the present invention should be included in the scope of protection of the present invention.
Claims
1. A data processing method, characterized in that: Applied to electronic equipment, the method comprises: Receiving a first operation of a user to start a first function; wherein after the first function is started, the electronic device starts a first service; the first service includes detecting and screening pictures and videos in a gallery, matching music subtitles to generate a first short film, and displaying the first short film on the desktop or negative one screen of the electronic device when the electronic device recognizes that the current scene meets the first schedule; When the first service interruption is detected, the data to be serialized is obtained, where the first service interruption includes any one of the following: the first service has been started and the first short film has not been generated, or the first short film has been generated and the electronic device recognizes that the current scene does not meet the first schedule, or the first short film has been generated and the electronic device recognizes that the current scene meets the first schedule and the electronic device is in a screen-off state; Obtain the data to be serialized, where the data to be serialized includes the original key and value; Traverse all the original keys and values in the data to be serialized, and obtain the data type of the value by using the reflection mechanism; When the data type of the value is a string type or a Boolean type, the original key is used as the new key; When the data type of the value is a list type, a tuple type, a dictionary type or a set type, the data types of the original key and the value are separated by a first separator, and the data type of the value and the data type of the element are separated by a second separator to obtain the new key; When the data type of the value is an integer, a floating point type, or a user-defined type, the data types of the original key and the value are separated by a third separator to obtain the new key; Convert all new key-value pairs consisting of the new key and the value into JSON data; When the first service is restored, the JSON data is obtained, and the JSON data is preprocessed into a JSON object; Traverse all the new key-value pairs in the JSON object; When the new key in the key-value pair does not include a separator, the new key is not parsed; When the new key in the key-value pair includes only the first separator, determine that the data before the first separator is the original key and the data after the first separator is the data type of the value; When the new key includes the first delimiter and at least one of the second delimiters, it is determined that the data before the first delimiter is the original key, and the data between the first delimiter and the first of the second delimiters after the first delimiter is the data type of the value; Restore the original key-value pair of the original key and the original value; An object is synthesized, and the first service is executed according to the object.
2. An electronic device, characterized in that: include: Processor and memory; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the electronic device performs the method of claim 1.
3. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to claim 1 is implemented.
4. A chip system, characterized in that: The system comprises at least one processor and a communication interface, wherein the communication interface and the at least one processor are interconnected via a line, and the at least one processor is used to run a computer program or instruction to execute the method according to claim 1.
5. A computer program product, characterized in that The invention comprises a computer program which, when being executed, causes a computer to execute the method as claimed in claim 1.
Citation Information
Patent Citations
Method, device and equipment for transmitting set type data
CN112491857A
Model data processing method and device, equipment and storage medium
CN115391696A