Method for converting JSON (JavaScript Object Notation) data into model data

Through the objectWithKeyValues ​​and objectArrayWithKeyValuesArray methods of the ZZLExtentsion framework, the problem of the cumbersome process of converting JSON data into model data is solved, efficient and concise data conversion is achieved, and development efficiency and accuracy are improved.

CN120162047APending Publication Date: 2025-06-17BEIYIN FINANCIAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510317638.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-18
Publication Date
2025-06-17

AI Technical Summary

Technical Problem

During the development of mobile banking apps, developers need to process a large amount of complex JSON data and convert it into easy-to-manage model data. The existing technology solutions are cumbersome and prone to errors, resulting in inefficient development.

Method used

By introducing the ZZLExtentsion framework, the objectWithKeyValues ​​and objectArrayWithKeyValuesArray methods are provided to automatically convert JSON data into model data, support the KeyValues ​​and KeyValuesArray formats, and provide the functions of replacing keys, allowing attribute names and ignoring attribute names, and supporting nested conversion of model data.

Benefits of technology

The conversion process of JSON data to model data is simplified, development efficiency is improved, error probability is reduced, and the conversion of complex data structures is supported, achieving fast and efficient data conversion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120162047A_ABST
    Figure CN120162047A_ABST
Patent Text Reader

Abstract

The invention discloses a conversion method for converting JSON (JavaScript Object Notation) data into model data. The conversion method comprises the following steps: an APP (Application) enters a running state; the method comprises the following steps of: introducing a ZZLExtentsion.h file; the server returns the JSON data; if the format of the JSON data is KeyValues, an objectWithKeyValues method of ZZLExtention is used, so that the JSON data is converted into model data, and if the format of the JSON data is KeyValues, the JSON data is converted into the model data by using an objectWithKeyValues method of ZZLExtention; and if the format of the JSON data is KeyValuesArray, an objectArrayWithKeyValuesArray method of ZZLExtention is used, so that a JSON data array is converted into a model data array, and when the format of the JSON data is KeyValuesArray, an objectArrayWithKeyValuesArray method of ZZLExtention is used for converting the JSON data array into the model data array. Model data nesting conversion and multi-level model data conversion are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of model data conversion, and in particular to a conversion method based on converting JSON data into model data. Background Art

[0002] When users use mobile banking apps to operate business processes, they need to process a large amount of complex JSON data from the server, which may include business process data, user details, loan product information, loan process information, business data information, user name, age and photo, etc. For app developers, it is crucial to easily convert JSON data into easy-to-manage model data. Reducing the tedious conversion process, reducing repetitive work, and reducing the probability of errors can help developers save time and energy during the development process and make the code more understandable.

[0003] Existing technical solutions:

[0004] 1. Convert JSON data into model data through the system's built-in KVC mode.

[0005] 2. Manually assign JSON data to model data.

[0006] 3. First convert the JSON data into NSDictionary, use the valueForKey or objectForKey method to get the corresponding value of the field, and then assign it to the model data.

[0007] 4. Convert JSON data into model data through JsonModel and JSONKit framework. Summary of the invention

[0008] In view of the above problems, the present invention is proposed to provide a conversion method based on converting JSON data into model data, which overcomes the above problems or at least partially solves the above problems.

[0009] According to one aspect of the present invention, a conversion method based on converting JSON data into model data is provided, and the conversion method comprises:

[0010] The APP enters the running state;

[0011] Import ZZLExtentsion.h file;

[0012] The server returns JSON data;

[0013] If the JSON data format is KeyValues, use the objectWithKeyValues ​​method of ZZLExtentsion to convert the JSON data into model data;

[0014] If the JSON data format is KeyValuesArray, use the objectArrayWithKeyValuesArray method of ZZLExtentsion to convert the JSON data array into a model data array.

[0015] Optionally, if the JSON data format is KeyValues, using the objectWithKeyValues ​​method of ZZLExtentsion to convert the JSON data into model data specifically includes:

[0016] Call the objectWithKeyValues ​​method;

[0017] Call the setkeyValues:context: method to convert JSON data into model data;

[0018] Traverse all attributes of the current class and parent class;

[0019] Determine whether it is a basic class from the Foundation library. If so, assign values ​​to the attributes through KVC and convert them into objects.

[0020] Determine whether the loop is finished. If so, end the determination. Otherwise, continue to determine whether it is a basic class from the Foundation library.

[0021] Optionally, if the JSON data format is KeyValuesArray, the objectArrayWithKeyValuesArray method of ZZLExtentsion is used to convert the JSON data array into a model data array, specifically including:

[0022] Call the objectArrayWithKeyValuesArray method;

[0023] Traverse element A in the incoming JSON data Array;

[0024] Determine whether the element A is an array. If so, continue to call

[0025] objectArrayWithKeyValuesArray method;

[0026] Otherwise, call the objectWithKeyValues ​​method.

[0027] Optionally, the replacedKeyFromPropertyName method of ZZLExtentsion is used to replace the inconsistent key in the JSON data and the key in the model data.

[0028] Optionally, the allowedPropertyNames method of ZZLExtentsion is used to set the property names specified in the model data to allow conversion to and from JSON data.

[0029] Optionally, the ignoredPropertyNames method of ZZLExtentsion is used to set the property names specified in the model data to be ignored and not converted to JSON data.

[0030] Optionally, the isClassFromFoundation method of the ZZLFoundation class is used to determine whether a class is a foundation class and its subclasses, and then the JSON data and model data are converted.

[0031] Optionally, the ZZLPropertyType records the type of a property. The property type in ZZLProperty is recorded using ZZLPropertyType. The ZZLPropertyType class contains a type identifier, whether it is a basic numeric type, a source framework, and whether KVC is supported. It provides property type information in the conversion between JSON data and model data.

[0032] The present invention provides a conversion method based on converting JSON data into model data, the conversion method comprising: APP enters running state; introduces ZZLExtentsion.h file; server returns JSON data; if the JSON data format is KeyValues, the objectWithKeyValues ​​method of ZZLExtentsion is used to convert JSON data into model data; if the JSON data format is KeyValuesArray, the objectArrayWithKeyValuesArray method of ZZLExtentsion is used to convert JSON data array into model data array. Nested conversion of model data and multi-level model data conversion are realized.

[0033] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.

[0035] Figure 1 A flowchart of a conversion method based on converting JSON data into model data provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0036] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0037] The terms "comprises" and "having" and any variations thereof in the description embodiments, claims and drawings of the present invention are intended to cover non-exclusive inclusions, for example, including a series of steps or units.

[0038] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments.

[0039] like Figure 1 As shown, a conversion method based on converting JSON data into model data includes: the APP enters the running state; the ZZLExtentsion.h file is introduced; the server returns the JSON data; if the JSON data format is KeyValues, the objectWithKeyValues ​​method of ZZLExtentsion is used to convert the JSON data into model data; if the JSON data format is KeyValuesArray, the objectArrayWithKeyValuesArray method of ZZLExtentsion is used to convert the JSON data array into the model data array.

[0040] To convert JSON data into model data based on ZZLExtentsion, you need to introduce the ZZLExtentsion.h file into the app public class. When JSON data needs to be converted into model data, the model data calls different methods of ZZLExtentsion to achieve the conversion according to the format of the JSON data.

[0041] When the JSON data format is KeyValues, use the objectWithKeyValues ​​method of ZZLExtentsion to convert the JSON data into model data. When the JSON data format is KeyValuesArray, use the objectArrayWithKeyValuesArray method of ZZLExtentsion to convert the JSON data array into the model data array.

[0042] Use the replacedKeyFromPropertyName method of ZZLExtentsion to replace the key in the JSON data that is inconsistent with the key in the model data.

[0043] Use the allowedPropertyNames method of ZZLExtentsion to set the property names specified in the model data to allow conversion to and from JSON data.

[0044] Use the ignoredPropertyNames method of ZZLExtentsion to set the property names specified in the model data to be ignored and not converted to JSON data.

[0045] Use the isClassFromFoundation method of the ZZLFoundation class to determine whether a class is a foundation class or its subclass, and then convert the JSON data and model data.

[0046] The class that uses the ZZLProperty class to record property information contains all the information of the property, such as property type, name, source, etc.

[0047] ZZLPropertyType records the type of a property. For example, the property type in ZZLProperty is recorded using ZZLPropertyType. The ZZLPropertyType class contains the type identifier, whether it is a basic numeric type, the source framework, whether KVC is supported, etc. It provides property type information in the conversion between JSON data and model data.

[0048] The NSObject+ZZLKeyValue class provides an interface for converting between all model data and JSON data.

[0049] NSObject+ZZLProperty traverses all members of the model data, obtains the attributes in the model data, and converts them into a ZZLProperty attribute model list. The ZZLProperty class is used to save attributes for model data and JSON data conversion.

[0050] Use the newValueFrom0ldValue method to convert dates and strings to nil.

[0051] Use the class_copyPropertyList method in runtime to get all the properties of the model data class. Use property_getName to get the property name. Generate the type of the attribute object based on the property_getAttributes information.

[0052] Use the objc_setAssociatedObject method in the runtime to add an associated object to the ZZLProperty class object, use property as the key, and associate the propertyObj instance object.

[0053] Create a static dictionary to ensure that the dictionary will always exist in memory while the program is running, thus achieving the purpose of caching.

[0054] First, get the model data class attribute list from the cache. If it is not in the cache, iterate over each attribute in the model data class, get the attribute list, and then save it to the cache.

[0055] According to the property type in ZZLProperty, process the property and get the property value. According to the property name, assign the property value through KVC.

[0056] With the introduction of the ZZLExtentsion framework, the model data class directly calls the conversion method without modifying any model data class code.

[0057] Introduce the ZZLExtentsion framework to reduce the size of AppDelegate.

[0058] Implement nested model data conversion, multi-level model data conversion, and define other model data arrays in model data.

[0059] The property name in the model data is inconsistent with the key in the JSON data.

[0060] Process large amounts of complex JSON data into model data with low memory usage.

[0061] Setting the specified attribute name in the model data allows conversion to and from JSON data.

[0062] The attribute name specified in the setting model data is ignored and no conversion to JSON data is performed.

[0063] Creating a large amount of model data will cause excessive memory usage and occupy the phone's running memory.

[0064] Solve the efficiency issue of converting JSON data into model data to achieve fast and efficient conversion.

[0065] Beneficial effects:

[0066] 1. Realize nested conversion of model data and multi-level model data conversion.

[0067] 2. With its ultra-lightweight characteristics, it provides an extremely convenient way of data conversion.

[0068] 3. Fast conversion speed, simple use, low threshold for use, no pollution, no intrusion.

[0069] 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 substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A conversion method based on JSON data into model data, characterized in that: The conversion method comprises: The APP enters the running state; Import ZZLExtentsion.h file; The server returns JSON data; If the JSON data format is KeyValues, use the objectWithKeyValues ​​method of ZZLExtentsion to convert the JSON data into model data; If the JSON data format is KeyValuesArray, use the objectArrayWithKeyValuesArray method of ZZLExtentsion to convert the JSON data array into a model data array.

2. The method for converting JSON data into model data according to claim 1, characterized in that: If the JSON data format is KeyValues, the objectWithKeyValues ​​method of ZZLExtentsion is used to convert the JSON data into model data, specifically including: Call the objectWithKeyValues ​​method; Call the setkeyValues:context: method to convert JSON data into model data; Traverse all attributes of the current class and parent class; Determine whether it is a basic class from the Foundation library. If so, assign values ​​to the attributes through KVC and convert them into objects. Determine whether the loop is finished. If so, end the determination. Otherwise, continue to determine whether it is a basic class from the Foundation library.

3. The method for converting JSON data into model data according to claim 2, characterized in that: If the JSON data format is KeyValuesArray, the objectArrayWithKeyValuesArray method of ZZLExtentsion is used to convert the JSON data array into a model data array, specifically including: Call the objectArrayWithKeyValuesArray method; Traverse element A in the incoming JSON data Array; Determine whether the element A is an array. If so, continue to call objectArrayWithKeyValuesArray method; Otherwise, call the objectWithKeyValues ​​method.

4. The method for converting JSON data into model data according to claim 1, characterized in that: The replacedKeyFromPropertyName method of ZZLExtentsion is used to replace the inconsistency between the key in the JSON data and the key in the model data.

5. The method for converting JSON data into model data according to claim 1, characterized in that: The allowedPropertyNames method of ZZLExtentsion is used to set the property names specified in the model data to allow conversion to JSON data.

6. The method for converting JSON data into model data according to claim 1, characterized in that: The ignoredPropertyNames method of ZZLExtentsion is used to set the property names specified in the model data to be ignored and not converted to JSON data.

7. The method for converting JSON data into model data according to claim 1, characterized in that: The isClassFromFoundation method of the ZZLFoundation class is used to determine whether a class is a foundation class and its subclasses, and then the JSON data and model data are converted.

8. The method for converting JSON data into model data according to claim 1, characterized in that: The ZZLPropertyType records the type of a property. The property type in ZZLProperty is recorded using ZZLPropertyType. The ZZLPropertyType class contains a type identifier, whether it is a basic numeric type, the source framework, and whether KVC is supported. It provides property type information in the conversion between JSON data and model data.