CN112579151A - Method and device for generating model file - Google Patents

Method and device for generating model file Download PDF

Info

Publication number
CN112579151A
CN112579151A CN201910943856.5A CN201910943856A CN112579151A CN 112579151 A CN112579151 A CN 112579151A CN 201910943856 A CN201910943856 A CN 201910943856A CN 112579151 A CN112579151 A CN 112579151A
Authority
CN
China
Prior art keywords
file
character string
dictionary
key
model
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.)
Pending
Application number
CN201910943856.5A
Other languages
Chinese (zh)
Inventor
徐记军
于学良
尹华东
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201910943856.5A priority Critical patent/CN112579151A/en
Publication of CN112579151A publication Critical patent/CN112579151A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Library & Information Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method and a device for generating a model file, and relates to the technical field of computers. One embodiment of the method comprises: calling an entry function, and transmitting input parameters when the entry function is called; wherein the input parameters include target data and a model file name; analyzing the target data, and storing the analyzed object into the created class name file and the created class object file according to the object type; traversing the elements of the class object file, and generating a model file corresponding to the model file name according to the data type of the elements and the class name file and a set file format. According to the method, the input parameters including the target data and the model file name are transmitted by calling the entry function, so that the model file is automatically generated according to the transmitted parameters, the creation time of the model file is shortened, the accuracy is high, and the development efficiency is improved.

Description

Method and device for generating model file
Technical Field
The invention relates to the field of computers, in particular to a method and a device for generating a model file.
Background
In the development joint debugging process of an IOS Application (APP), if data returned by a server interface is json (javascript object specification) data, the APP needs to manually create a Model (Model) file and attributes in the Model file according to the json format, and then perform conversion through a third-party framework, such as YYModel, to display the data according to Model information. Wherein json is a lightweight data exchange format, and YYModel is a lightweight json model automatic conversion library.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
the prior art requires manual analysis and manual creation of model files. Under the condition that json data returned by the interface are more, the model file is created in the mode, so that the efficiency is low, the accuracy is low, and the APP development efficiency is low.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for generating a model file, where an entry function is called to input an input parameter including target data and a name of the model file, so as to automatically generate the model file according to the input parameter, reduce creation time of the model file, achieve high accuracy, and improve development efficiency.
To achieve the above object, according to an aspect of an embodiment of the present invention, a method for generating a model file is provided.
The method for generating the model file comprises the following steps: calling an entry function, and transmitting input parameters when the entry function is called; wherein the input parameters include target data and a model file name; analyzing the target data, and storing the analyzed object into the created class name file and the created class object file according to the object type; traversing the elements of the class object file, and generating a model file corresponding to the model file name according to the data type of the elements and the class name file and a set file format.
Optionally, the class object file includes a class name attribute and a class attribute; the step of storing the analyzed object into the created class name file and the created class object file according to the object type includes: if the object is not an array or a dictionary, adding the initialized temporary dictionary as the class attribute to the class object file; if the object is an array, removing non-dictionary type data in the array, combining the removed data into a first new dictionary, traversing keys in the first new dictionary, and storing the first new dictionary into the created class name file and the created class object file according to the type of key values; and if the object is a dictionary, traversing keys in the dictionary, and storing the dictionary to the created class name file and the created class object file according to the type of the key value.
Optionally, the input parameters further include: sub-model suffix name; storing the dictionary to the created class name file and the created class object file according to the key value type, wherein the method comprises the following steps: if the key value type is null or a character string, taking the key as the key of the temporary dictionary, taking the value of the temporary dictionary as null or the character string correspondingly, and adding the temporary dictionary as the category attribute into the category object file; if the key value type is a dictionary, splicing the key and the sub-model suffix name to obtain a first splicing character string, traversing whether the first splicing character string exists in the class name file, if so, adding a first identifier in the first splicing character string to obtain a first new splicing character string, and after traversing is finished, adding the first splicing character string or the first new splicing character string to the class name file; and taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is the first splicing character string or the first new splicing character string, and the temporary dictionary is taken as the category attribute and added into the category object file.
Optionally, the input parameters further include: sub-model suffix name; storing the dictionary to the created class name file and the created class object file according to the key value type, wherein the method comprises the following steps: if the key value type is an array, removing non-dictionary type data in the array, merging the removed data into a second new dictionary, and if the second new dictionary is empty, taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is a set character string; if the second new dictionary is not empty, the key and the sub-model suffix name are spliced to obtain a second splicing character string, whether the second splicing character string exists in the class name file is traversed, if yes, a first identifier is added into the second splicing character string to obtain a second new splicing character string, and after traversal is completed, the second splicing character string or the second new splicing character string is added into the class name file; and taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is the splicing of the second splicing character string or the second new splicing character string and the set character string, and the temporary dictionary is taken as the category attribute and added into the class object file.
Optionally, the input parameters further include: sub-model suffix name; storing the dictionary to the created class name file and the created class object file according to the key value type, wherein the method comprises the following steps: if the key value type is other types, obtaining a class description character string, and if the class description character string contains an NSCFBoolean character string, taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is a Boolean character string; wherein the other types are types other than null, character strings, dictionaries, and arrays; if the class description character string contains NSCFNumber character strings and is of a long type, taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is an integer character string; and if the class description character string contains NSCFNumber character strings and is of a double type, using the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is a double-precision character string.
Optionally, the model file comprises a model declaration file; generating a model declaration file corresponding to the model file name according to a set file format, wherein the model declaration file comprises: acquiring the category attribute of the current element of the class object file and the key of the category attribute, and declaring a first temporary character string; traversing the keys of the category attributes and the elements of the keys, matching the current elements of the keys with set matching conditions, and assigning values to the first temporary character strings according to matching results; and the splicing type definition character string and the assigned first temporary character string are written into a file to generate a model statement file.
Optionally, the matching condition includes any one or more of the following: whether the type of the value corresponding to the current element of the key is null, a character string, Boolean, double precision or an integer, whether the current element of the key starts with an array character string, and whether the class name file contains the current element.
Optionally, the model file comprises a model implementation file; generating the model implementation file corresponding to the model file name according to a set file format, wherein the model implementation file comprises: setting a value of a second temporary character string according to the type of the current element of the class object file; initializing a third temporary character string, traversing keys in the category attribute in the category object file, and assigning a value to the third temporary character string under the condition that a current key starts with an array and the residual character string after intercepting the array of the current key is not 0; after traversing is finished, updating the third temporary character string by combining the second temporary character string according to the length of the third temporary character string; and the fourth splicing character string is written into a file to generate a model implementation file.
Optionally, the input parameters further include: a model file storage address; the method further comprises the following steps: outputting the model file to a designated storage location; wherein the designated storage location is the model file storage address.
Optionally, the method further comprises: if the key value type is a dictionary, judging whether repeated keys exist in a parent dictionary of the current dictionary; and if repeated keys exist, adding a second identifier in the corresponding key of the parent dictionary, and taking the key added with the second identifier as the corresponding key of the current dictionary.
To achieve the above object, according to another aspect of the embodiments of the present invention, an apparatus for generating a model file is provided.
The device for generating the model file of the embodiment of the invention comprises: the function calling module is used for calling an entry function and transmitting input parameters when the entry function is called; wherein the input parameters include target data and a model file name; the analysis storage module is used for analyzing the target data and storing the analyzed object to the created class name file and the created class object file according to the object type; and the traversal generation module is used for traversing the elements of the class object file and generating a model file corresponding to the model file name according to the data type of the elements and the class name file and a set file format.
Optionally, the class object file includes a class name attribute and a class attribute; the analysis storage module is further configured to: if the object is not an array or a dictionary, adding the initialized temporary dictionary as the class attribute to the class object file; if the object is an array, removing non-dictionary type data in the array, combining the removed data into a first new dictionary, traversing keys in the first new dictionary, and storing the first new dictionary into the created class name file and the created class object file according to the type of key values; and if the object is a dictionary, traversing keys in the dictionary, and storing the dictionary to the created class name file and the created class object file according to the type of the key value.
Optionally, the input parameters further include: sub-model suffix name; the analysis storage module is further configured to: if the key value type is null or a character string, taking the key as the key of the temporary dictionary, taking the value of the temporary dictionary as null or the character string correspondingly, and adding the temporary dictionary as the category attribute into the category object file; if the key value type is a dictionary, splicing the key and the sub-model suffix name to obtain a first splicing character string, traversing whether the first splicing character string exists in the class name file, if so, adding a first identifier in the first splicing character string to obtain a first new splicing character string, and after traversing is finished, adding the first splicing character string or the first new splicing character string to the class name file; and taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is the first splicing character string or the first new splicing character string, and the temporary dictionary is taken as the category attribute and added into the category object file.
Optionally, the input parameters further include: sub-model suffix name; the analysis storage module is further configured to: if the key value type is an array, removing non-dictionary type data in the array, merging the removed data into a second new dictionary, and if the second new dictionary is empty, taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is a set character string; if the second new dictionary is not empty, the key and the sub-model suffix name are spliced to obtain a second splicing character string, whether the second splicing character string exists in the class name file is traversed, if yes, a first identifier is added into the second splicing character string to obtain a second new splicing character string, and after traversal is completed, the second splicing character string or the second new splicing character string is added into the class name file; and taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is the splicing of the second splicing character string or the second new splicing character string and the set character string, and the temporary dictionary is taken as the category attribute and added into the class object file.
Optionally, the input parameters further include: sub-model suffix name; the analysis storage module is further configured to: if the key value type is other types, obtaining a class description character string, and if the class description character string contains an NSCFBoolean character string, taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is a Boolean character string; wherein the other types are types other than null, character strings, dictionaries, and arrays; if the class description character string contains NSCFNumber character strings and is of a long type, taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is an integer character string; and if the class description character string contains NSCFNumber character strings and is of a double type, using the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is a double-precision character string.
Optionally, the model file comprises a model declaration file; the traversal generation module is further configured to: acquiring the category attribute of the current element of the class object file and the key of the category attribute, and declaring a first temporary character string; traversing the keys of the category attributes and the elements of the keys, matching the current elements of the keys with set matching conditions, and assigning values to the first temporary character strings according to matching results; and the splicing type definition character string and the assigned first temporary character string are written into a file to generate a model statement file.
Optionally, the matching condition includes any one or more of the following: whether the type of the value corresponding to the current element of the key is null, a character string, Boolean, double precision or an integer, whether the current element of the key starts with an array character string, and whether the class name file contains the current element.
Optionally, the model file comprises a model implementation file; the traversal generation module is further configured to: setting a value of a second temporary character string according to the type of the current element of the class object file; initializing a third temporary character string, traversing keys in the category attribute in the category object file, and assigning a value to the third temporary character string under the condition that a current key starts with an array and the residual character string after intercepting the array of the current key is not 0; after traversing is finished, updating the third temporary character string by combining the second temporary character string according to the length of the third temporary character string; and the fourth splicing character string is written into a file to generate a model implementation file.
Optionally, the input parameters further include: a model file storage address; the device further comprises: the file output module is used for outputting the model file to a specified storage position; wherein the designated storage location is the model file storage address.
Optionally, the apparatus further comprises: the repeated key processing module is used for judging whether repeated keys exist in a parent dictionary of the current dictionary or not if the key value type is a dictionary; and if repeated keys exist, adding a second identifier in the corresponding key of the parent dictionary, and taking the key added with the second identifier as the corresponding key of the current dictionary.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided an electronic apparatus.
An electronic device of an embodiment of the present invention includes: one or more processors; a storage device, configured to store one or more programs, which when executed by the one or more processors, cause the one or more processors to implement a method for generating a model file according to an embodiment of the present invention.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided a computer-readable medium.
A computer-readable medium of an embodiment of the present invention stores thereon a computer program that, when executed by a processor, implements a method of generating a model file of an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: by calling an entry function, input parameters including target data and a model file name are transmitted, so that a model file is automatically generated according to the transmitted parameters, the creation time of the model file is reduced, the accuracy is high, and the development efficiency is improved; processing the object according to the object type obtained by analyzing the target data so as to automatically store the object into a corresponding class name file and a corresponding class object file; according to the set file format, a model declaration file corresponding to the name of the model file and a model implementation file are automatically generated, so that the creation time of the model file is further reduced, and the development efficiency is improved; outputting the model file to a storage position specified by the input parameters, and facilitating subsequent acquisition of the model file for further processing; for the condition that a sub dictionary exists in the dictionary, before the keys corresponding to the sub dictionary are processed, whether repeated keys exist in the father dictionary is judged, so that the keys corresponding to the sub dictionary and the keys corresponding to the father dictionary cannot be repeated.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a diagram illustrating the main steps of a method for generating a model file according to a first embodiment of the present invention;
FIG. 2 is a schematic diagram illustrating the generation principle of a model file according to a second embodiment of the present invention;
FIG. 3 is a schematic main flow chart of a method for generating a model file according to a second embodiment of the present invention;
FIG. 4 is a schematic diagram illustrating the generation principle of a model declaration file and a model implementation file according to a third embodiment of the present invention;
FIG. 5 is a schematic main flow chart of a method for generating a model file according to a third embodiment of the present invention;
FIG. 6 is a schematic diagram of the main modules of a model file generation apparatus according to an embodiment of the present invention;
FIG. 7 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
FIG. 8 is a schematic diagram of a computer apparatus suitable for use in an electronic device to implement an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram of main steps of a method for generating a model file according to a first embodiment of the present invention. As shown in fig. 1, a method for generating a model file according to a first embodiment of the present invention mainly includes the following steps:
step S101: calling an entry function, and transmitting input parameters when the entry function is called; wherein the input parameters include target data and a model file name. When the model file needs to be generated, an entry function in a Software Development Kit (SDK) is called, wherein the entry function comprises a plurality of input parameters. The input parameters are passed in while the entry function is called. The target data in the input parameters is the data that the server returns to the APP, such as json data.
Step S102: and analyzing the target data, and storing the analyzed object to the created class name file and the created class object file according to the object type. The class name file is used for storing all class names; the class object file is used for storing class information, including a class name attribute and a class attribute. If the object is not an array or a dictionary, adding the initialized temporary dictionary as a category attribute to the class object file; if the object is an array, removing non-dictionary type data in the array, combining the removed data into a first new dictionary, traversing keys in the first new dictionary, and storing the first new dictionary into the created class name file and the created class object file according to the key value type; and if the object is a dictionary, traversing keys in the dictionary, and storing the dictionary to the created class name file and the created class object file according to the key value type.
Step S103: traversing the elements of the class object file, and generating a model file corresponding to the model file name according to the data type of the elements and the class name file and a set file format. The model files include a model declaration file and a model implementation file. The generation process of the model statement file comprises the following steps: traversing the elements of the class object file, acquiring the class attribute of the current element of the class object file and the key of the class attribute, and declaring a first temporary character string; traversing keys of the category attributes and elements of the keys, matching current elements of the keys with set matching conditions, and assigning values to the first temporary character strings according to matching results; and the splicing type definition character string and the assigned first temporary character string are written into a file to generate a model statement file.
And after the model declaration file is successfully created, a model implementation file is generated. The generation process of the model implementation file comprises the following steps: traversing the elements of the class object file, and setting the value of a second temporary character string according to the type of the current element of the class object file; initializing a third temporary character string, traversing keys in the category attributes in the category object file, and assigning a value to the third temporary character string under the condition that the current key starts with an array and the residual character string after intercepting the array of the current key is not 0; after traversing is finished, updating the third temporary character string by combining the second temporary character string according to the length of the third temporary character string; and the fourth splicing character string is written into the file to generate a model implementation file.
Fig. 2 is a schematic diagram illustrating a principle of generating a model file according to a second embodiment of the present invention. As shown in fig. 2, taking target data as json data as an example, the model generation process of the embodiment of the present invention mainly includes: analyzing the json data model and whether the nested submodel exists, processing the analyzed data, generating a model statement file and a model implementation file, and outputting the model statement file and the model implementation file to a specified storage position.
When the model file needs to be generated, an entry function, a makeJson function and a modelWithFileName function contained in the SDK are sequentially called according to the sequence in the figure. The entry function includes a createyymodel withjson function and a creatmjmodelwithjson function, and includes a plurality of input parameters. The makeJson function is used to validate the input parameters. And after the verification is passed, automatically calling a modelWithFileName function to analyze json data in the input parameters, generating a model file, and outputting the model file to a specified storage position. The SDK source code may then be integrated through github or cocoapods. Wherein, github is a managed platform facing to open source and private software project; cocoapods are class library management tools for IOS.
Fig. 3 is a schematic main flow diagram of a method for generating a model file according to a second embodiment of the present invention. As shown in fig. 3, the method for generating a model file according to the second embodiment of the present invention mainly includes the following steps:
step S301: the application calls the entry function of the SDK, and inputs the input parameters when the entry function is called. The application program sends a network request to the server, and the server feeds back json data to the application program. The SDK is imported into the application and functions within the SDK are invoked where the network requests return data. The main class is a JsonToModel class, and the JsonToModel class contains an entry function of json data and a function for generating a model file.
The entry function may be multiple, and its input parameters may include: json data, model file name and model file storage address. In an embodiment, the entry function is 2 create functions with the input parameters, and the first entry function is:
-(BOOL)createYYModelWithJson:(id)json fileName:(NSString*)fileName extensionName:(NSString*)extensionName fileURL:(NSURL*)url error:(Error)error;
the second entry function is:
-(BOOL)createMJModelWithJson:(id)json fileName:(NSString*)fileName extensionName:(NSString*)extensionName fileURL:(NSURL*)url error:(Error)error;
step S302: the application calls the makeJson function of the SDK to verify the input parameters. The check logic is as follows: and whether the json data is empty (nil) or not, and if so, returning directly. And if the storage address of the model file is empty, directly returning. And if the model file name is null, setting a default file name, such as 'TestModel'. And whether the sub-model suffix name is null or not, and if the sub-model suffix name is null, setting a default sub-model suffix name. For example, if the called entry function is createYYModelWithJson, the submodel suffix name defaults to yy _ class; if the called entry function is createMJModelWithJson, the sub-model suffix name defaults to mj _ class.
Step S303: and the application program calls a modelWithFileName function of the SDK to process json data, generate a model statement file and a model implementation file, and outputs the model statement file and the model implementation file to a specified storage position. And the appointed storage position is a model file storage address in the input parameters. The modelWithFileName function includes: a willFormat function, a formatDataToClassWidth function, a returnHStringWithFileName function, a hStringWithClassObject function, a returnMStringWithFileName function, an mStringWithClassObject function.
The winlformat function is used to create class name files and class object files. In the embodiment, the class name file is a classNames array, and the class object file is a classObjects array. The classNames array is used for storing all class name character strings; the classObjects array is used to store class information, and contains a class name (className) attribute and a class Property attribute.
The format DataToClassWidth function is a main function, and the implementation logic is a recursive idea. The function is used for storing an object obtained by analyzing the json data into a class name file and a class object file according to the object type; and generating a model declaration file and a model realization file according to a set file format by traversing the elements of the class object file and according to the data types and the class name files of the elements.
The return HStringWithFileName function and the hStringWithClassObject function are used to output the model declaration file.
The return MString WithFileName function and the mTringWithClassObject function are used to output the model realization file.
In a preferred embodiment, the implementation process of storing the object obtained by analyzing the json data into the class name file and the class object file according to the object type by the format datatoclasspath function is as follows:
if the object (corresponding to the fact in step S505) is not an array or dictionary, the initialized temporary dictionary (corresponding to tempDic in step S504) is added as a class attribute to the class object file.
If the object is an array, removing the non-dictionary type data in the array, merging the removed data into a first new dictionary, traversing the keys in the first new dictionary, and storing the first new dictionary into the created class name file and the created class object file according to the type of the key value (corresponding to temp in step S505).
And if the object is a dictionary, traversing keys in the dictionary, and storing the dictionary to the created class name file and the created class object file according to the key value type.
In another preferred embodiment, the implementation process of generating the model declaration file corresponding to the model file name by the format datatoclasspath function according to the set file format is as follows:
acquiring the category attribute and the key of the category attribute of the current element of the class object file, and declaring a first temporary character string (corresponding to temp in step S506); traversing keys of the category attributes and elements of the keys, matching current elements of the keys with set matching conditions, and assigning values to the first temporary character strings according to matching results; the concatenation class definition string (corresponding to classtring in step S506) and the assigned first temporary string are written into a file, and the obtained third concatenation string (corresponding to classtring + "@ end in step S506) is written into the file to generate a model declaration file.
In another preferred embodiment, the implementation process of generating the model implementation file corresponding to the model file name according to the set file format by the format datatoclasspath function is as follows:
setting the value of a second temporary character string (corresponding to stringa-d in step S508) according to the type of the current element of the class object file; initializing a third temporary character string (corresponding to strings in step S508), traversing the keys in the category attributes in the class object file, and assigning a value to the third temporary character string when the current key starts with an array and the remaining character string after intercepting the array of the current key is not 0;
after traversing is finished, updating the third temporary character string by combining the second temporary character string according to the length of the third temporary character string; the fourth splicing character string (corresponding to "@ duplication" + classObj. className + "of step S508) obtained by the splicing type realization character string (corresponding to" @ duplication "+ classObj. className + strings +" end "of step S508) is written into the file to generate the model realization file.
And the external part only needs to import source codes into the project, and calls the two entry functions in the step S301 when the model needs to be generated, and the internal part of the SDK can automatically generate a model file to a specified storage position according to the input parameters. The time consumption of the whole model generation process is not more than 0.1 second, and the time for manually creating and analyzing the model is reduced.
Fig. 4 is a schematic diagram of the generation principle of the model declaration file and the model implementation file in the third embodiment of the present invention. As shown in fig. 4, after the modelWithFileName function is called, the wireform function, the formatdatatoclasspath function, the returnhstringtwithfilename function, the hslingwithclasbject function, the returnmstringapilename function, and the mstringaplastobject function are called in sequence in the figure, and finally, a model declaration file and a model implementation file are generated, and a specified storage location is output. The model files of the IOS include an h file and an m file. In the embodiment, the model declaration file is an h file, and the model implementation file is an m file.
Fig. 5 is a schematic main flow diagram of a method for generating a model file according to a third embodiment of the present invention. As shown in fig. 5, the method for generating a model file according to the third embodiment of the present invention includes the following steps:
step S501: and calling an entry function, and when the entry function is called, inputting input parameters. Wherein, the input parameters include: json data, model file name, sub-model suffix name, model file storage address and analyzed error information. A sub-model herein refers to a model within a model.
Step S502: checking the input parameters, judging whether the checking is passed, and if the checking is passed, executing the step S503; and if not, feeding back an error prompt. In an embodiment, the function of this step is implemented by calling a makeJson function.
Step S503: the classNames array and classObjects array are initialized. The classObjects array includes a className attribute and a classPropertyAttribute. In an embodiment, the function of this step is realized by calling a winformat function.
Step S504: an object classObj is created, and the dictionary tempDic is initialized. Creating an object classObj by using a system method classObject.
Step S505: and storing the object into a classNames array and a classObjects array according to the object type of the object of the parsed json data. The specific storage process is as follows:
if the ditt in the format DataToClassWidth function parameter is not an array or a dictionary, the classPropertyAttribute of classObj is directly assigned as tempDic, and the classObjects array is added to the classObj element.
If the dit is an array or a dictionary, obtaining a dictionary object (assuming as the dic) according to a first processing logic of a special case, traversing all keys in the dic, assuming that the dic [ key ] is temp, judging the temp type according to a system method of isKindoOfClass, and carrying out the following processing according to the judgment result:
(1) if temp is of the Null (NSNull) type, then the key of tempDic is the key within dic and value is the Null string.
(2) If temp is of the string (NSString) type, then the key of tempDic is the key within dic and value is the NSString string.
(3) If temp is of a dictionary (NSDirectionary) type and indicates that a sub-dictionary is arranged in the dictionary, splicing key and a parameter extensionName character string in a format DataToClass function to obtain a first spliced character string; traversing the classNames array to determine whether the first splicing character string exists, if so, adding a first identifier, such as a sub character string, in front of the first splicing character string to obtain a first new splicing character string.
And after traversing is finished, adding the first splicing character string or the first new splicing character string into the classNames array. the key of tempDic is the key of dic, and value is the first splicing string or the first new splicing string. And then recursively calling a format DataToClassWith function, wherein the function parameters are temp respectively, and the finally processed splicing character string (namely the first splicing character string or the first new splicing character string) is followed by the sub-model suffix. Among them, NSDictionary is a key-value container used in IOS.
(4) If temp is of the array (NSArray) type, then the first piece of processing logic according to the special case gets the second new dictionary dicts, if dicts is empty, tempDic's key is dic's key, value is JDNSArray0 string. If dicts is not empty, temp is indicated as a model array. And splicing the key and the extensionName character string of the inner parameter of the format DataToClass function to obtain a second spliced character string. Traversing the classNames array to determine whether the second splicing character string exists, and if so, adding a first identifier, such as a sub character string, in front of the second splicing character string to obtain a second new splicing character string.
And after traversing, adding a second splicing character string or a second new splicing character string str into the classNames array, wherein the key of tempDic is the key of dic, and the value is the string added with the JDNSArray before the str. And then recursively calling a format DataToClassWith function, wherein the function parameters are dicts, str and the suffix name of the sub-model respectively.
(5) If temp is not of the above four types, a class descriptor string classDescription is obtained according to a system method [ [ temp class ] description ]. If the class description character string contains NSCFBoolean character string, the key of tempDic is the key in dic, and the value is Boolean (BOOL) character string.
If the string NSCFNumber string is contained, a system method is used for obtaining (strcmp ([ temp obj CType ], @ encode (long)), if the string NSCFNumber string is equal to 0, the key of tempDic is the key in the dic, value is an integer (NSInteger) string, (strcmp ([ temp obj CType ], @ encode (double)) if the string NSCFNumber string is equal to 0, the key of empDic is the key in the dic, value is a double-precision (double) string.
After each key in the dic is circularly traversed, assigning the classPropertyAttribute of classObj to tempDic, and adding a classObjects element into a classObjects array.
Step S506: and creating public information through the fileName, traversing elements of the classObjects array, and creating character strings in the h file according to the h file format. Wherein, the public information is information such as class name, author, date, etc. The method comprises the following steps of creating a character string in an h file according to an h file format: assuming that the element in the classObjects array is classObj,
(1) splice "@ interface" + classObj. className + ": NSObject ", make the string classString.
(2) The classProperties property of classObj (the property type is dictionary) is obtained, and assumed to be dit, and all keys (arrays) in dit are obtained, assumed to be keys. All elements of the keys are traversed, and if the element is propertyName, the value (fact [ propertyName ]) corresponding to the element is object. The string temp is declared.
If object is equal to Null or NSString, temp is assigned as "@ property (innotomic, copy) NSString" + PropertyName.
If object is equal to BOOL, temp is assigned as "@ property (nonomic, assign) BOOL" + PropertyName.
If object is equal to Double, temp is assigned as "@ property (nomitic, assign) ble" + PropertyName.
If object is equal to NSInteger, temp is assigned as "@ property (nomitic, assign) NSInterger" + PropertyName.
If the object begins with a NSArray string, intercepting the string within the object other than NSArray assumes name, and if name equals string 0, temp is assigned "@ property" + PropertyName. If name is not equal to string 0, the value is "@ property (nonomic, strong) NSArray <% @ >" + name + propertyName.
If an object is contained within the classNames array, the temp assignment is "@ property (nonomic, strong)% @" + object + propertName. Let classsstring + temp.
(3) Returning to classsstring + "@ end" which is finally spliced.
Step S507: writing the finally spliced character string into the h file, and if the writing is successful, executing the step S508; and if the writing fails, feeding back an error prompt. And writing the spliced character string into the h file by a system method, namely, writeToFile. This file is the h file.
Step S508: and creating public information through the fileName, traversing elements of the classObjects array, and creating character strings in the m-file according to the m-file format. And if the h file is successfully created, the m file is created. The implementation process of creating the character string in the m file according to the m file format is as follows: assuming that the element in the classObjects array is classObj,
if the entry function is a YYModel type (as determined by the entry function, if the entry function is createyymodel withjson, it is denoted as YYModel type), let stringa @' + (NSDictionary) @ modelcusotpropertymapper { \\ n return @ { \\ n "; stringc @' + (NSDictionary) modalconnerpropertgenericclass { \\ n return @ { \\ n ";
if not, stringa @' + (NSDictionary) mj _ replacedKeyFromPropertyName { \\ n return @ { \\ n "; stringc @' + (NSDictionary) @ mj _ object classsinarray { \ n return @ { \\ n ";
NSString*stringb=@“};\n}\n”;
NSString*stringd=@“};\n}\n“;
the string strings are initialized.
Let the array keys be classObj. All elements within a key are traversed, assuming a key, let object be class obj.
If the object begins with NSArray, the string other than NSArray is intercepted, if the string is not equal to string 0, then strings ═[ NSStringStringWithFormat: @'% @ \ @, [% @ class ], \\ n ", strings, key, className ].
After the circulation is completed, judging whether the length of strings is greater than 0, if so, setting the strings to be string c + strings + string d; if equal to 0, strings is "". Finally, the character string in the m file is "@ instantiation" + classObj.
Step S509: writing the created final character string into the m file, and if the writing is successful, executing step S510; and if the writing fails, feeding back an error prompt. Calling the system function writeToFile writes the final string into the.m file. This file is the. In the embodiment, the functions of step S504 to step S509 are implemented by calling a format datatoclasspath function.
Step S510: and outputting the h file and the m file to a specified storage position. The designated storage location is the model file storage address of the input parameter. In an embodiment, the function of this step is implemented by calling a returnHStringWithFileName function, a hstingwithclasslobject function, a returnmstrigwithfilename function, and an mstringwithclasslobject function.
In a preferred embodiment, there are special cases, such as Json data support arrays and dictionaries, class names in sub models are the same as parent model names, Json data is empty or in an incorrect format, etc. The handling of special cases is explained below:
(1) json data supports arrays and dictionaries:
the only difference between the processing of arrays and dictionaries is that: the dictionary directly traverses all keys; the array is formed by removing internal non-dictionary type data, merging the data into a dictionary, and traversing all keys in the merged dictionary. The realization process of removing non-dictionary types from an array and merging data comprises the following steps:
initializing an array ary, traversing elements in the json array, and assuming the elements to be obj;
judging whether the element is a dictionary type according to a system method [ obj iskindoofclass: [ NSDictionary class ] ]; if yes, adding the data into the initialized array ary;
after the traversal is finished, if the elements in the ary are still empty, returning to the empty dictionary; if not, a dictionary is initialized (assumed to be dic), elements in the array ary are traversed (assumed to be aryObj), data is merged according to a system method [ dic addEntriesFromDirectionry: aryObj ], and the dic is returned after merging.
(2) The class name in the sub-model is the same as the parent model name:
when the key value corresponding to the sub-dictionary is processed in step S505, it is first determined whether there is a duplicate key in the parent dictionary, if so, the key corresponding to the parent dictionary is first taken out, and a second identifier, such as a fixed character string "sub _", is added before the key, as the key corresponding to the current sub-dictionary, so as to ensure that the key corresponding to the sub-dictionary and the key corresponding to the parent dictionary will not be duplicated. The child dictionary and the father dictionary respectively correspond to the child model and the father model.
(3) Processing incoming json data:
if the json data is empty or the format is incorrect, no processing is done. The key value in the dictionary, if of the NSNull type, is directly processed as NSString.
According to the method for generating the model file, the input parameters including the target data and the name of the model file are transmitted by calling the entry function, so that the model file is automatically generated according to the transmitted parameters, the creation time of the model file is shortened, the accuracy is high, and the development efficiency is improved; processing the object according to the object type obtained by analyzing the target data so as to automatically store the object into a corresponding class name file and a corresponding class object file; according to the set file format, a model declaration file corresponding to the name of the model file and a model implementation file are automatically generated, so that the creation time of the model file is further reduced, and the development efficiency is improved; outputting the model file to a storage position specified by the input parameters, and facilitating subsequent acquisition of the model file for further processing; for the condition that a sub dictionary exists in the dictionary, before the keys corresponding to the sub dictionary are processed, whether repeated keys exist in the father dictionary is judged, so that the keys corresponding to the sub dictionary and the keys corresponding to the father dictionary cannot be repeated.
Fig. 6 is a schematic diagram of main blocks of a model file generation apparatus according to an embodiment of the present invention. As shown in fig. 6, a device 600 for generating a model file according to an embodiment of the present invention mainly includes:
a function calling module 601, configured to call an entry function, and when the entry function is called, input parameters are transmitted; wherein the input parameters include target data and a model file name. When the model file needs to be generated, an entry function in the software development kit SDK is called, and the entry function comprises a plurality of input parameters. The input parameters are passed in while the entry function is called. The target data in the input parameters is the data that the server returns to the APP, such as json data.
And the analysis storage module 602 is configured to analyze the target data, and store the analyzed object in the created class name file and the created class object file according to the object type. The class name file is used for storing all class names; the class object file is used for storing class information, including a class name attribute and a class attribute. If the object is not an array or a dictionary, adding the initialized temporary dictionary as a category attribute to the class object file; if the object is an array, removing non-dictionary type data in the array, combining the removed data into a first new dictionary, traversing keys in the first new dictionary, and storing the first new dictionary into the created class name file and the created class object file according to the key value type; and if the object is a dictionary, traversing keys in the dictionary, and storing the dictionary to the created class name file and the created class object file according to the key value type.
And a traversal generating module 603, configured to traverse the element of the class object file, and generate a model file corresponding to the model file name according to the data type of the element and the class name file and according to a set file format. The model files include a model declaration file and a model implementation file. The generation process of the model statement file comprises the following steps: traversing the elements of the class object file, acquiring the class attribute of the current element of the class object file and the key of the class attribute, and declaring a first temporary character string; traversing keys of the category attributes and elements of the keys, matching current elements of the keys with set matching conditions, and assigning values to the first temporary character strings according to matching results; and the splicing type definition character string and the assigned first temporary character string are written into a file to generate a model statement file.
And after the model declaration file is successfully created, a model implementation file is generated. The generation process of the model implementation file comprises the following steps: traversing the elements of the class object file, and setting the value of a second temporary character string according to the type of the current element of the class object file; initializing a third temporary character string, traversing keys in the category attributes in the category object file, and assigning a value to the third temporary character string under the condition that the current key starts with an array and the residual character string after intercepting the array of the current key is not 0; after traversing is finished, updating the third temporary character string by combining the second temporary character string according to the length of the third temporary character string; and the fourth splicing character string is written into the file to generate a model implementation file.
In addition, the apparatus 600 for generating a model file according to the embodiment of the present invention may further include: a file output module and a repeat key processing module (not shown in fig. 6). The file output module is used for outputting the model file to a specified storage position; wherein the designated storage location is the model file storage address. The repeated key processing module is used for judging whether repeated keys exist in a parent dictionary of the current dictionary or not if the key value type is a dictionary; and if repeated keys exist, adding a second identifier in the corresponding key of the parent dictionary, and taking the key added with the second identifier as the corresponding key of the current dictionary.
As can be seen from the above description, by calling the entry function, the input parameters including the target data and the model file name are transmitted, so as to automatically generate the model file according to the transmitted parameters, thereby reducing the creation time of the model file, achieving high accuracy, and improving the development efficiency; processing the object according to the object type obtained by analyzing the target data so as to automatically store the object into a corresponding class name file and a corresponding class object file; according to the set file format, a model declaration file corresponding to the name of the model file and a model implementation file are automatically generated, so that the creation time of the model file is further reduced, and the development efficiency is improved; outputting the model file to a storage position specified by the input parameters, and facilitating subsequent acquisition of the model file for further processing; for the condition that a sub dictionary exists in the dictionary, before the keys corresponding to the sub dictionary are processed, whether repeated keys exist in the father dictionary is judged, so that the keys corresponding to the sub dictionary and the keys corresponding to the father dictionary cannot be repeated.
Fig. 7 illustrates an exemplary system architecture 700 of a method or apparatus for generating a model file to which embodiments of the present invention may be applied.
As shown in fig. 7, the system architecture 700 may include terminal devices 701, 702, 703, a network 704, and a server 705. The network 704 serves to provide a medium for communication links between the terminal devices 701, 702, 703 and the server 705. Network 704 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 701, 702, 703 to interact with a server 705 over a network 704, to receive or send messages or the like. Various communication client applications, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, and the like, may be installed on the terminal devices 701, 702, and 703.
The terminal devices 701, 702, 703 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 705 may be a server that provides various services, such as a background management server that an administrator processes using a call request sent by the terminal devices 701, 702, and 703. The background management server can call a function in the SDK to perform json data processing, and feed back a processing result (e.g., a generated model file) to the terminal device.
It should be noted that the method for generating the model file provided in the embodiment of the present application is generally executed by the server 705, and accordingly, the model file generating apparatus is generally provided in the server 705.
It should be understood that the number of terminal devices, networks, and servers in fig. 7 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The invention also provides an electronic device and a computer readable medium according to the embodiment of the invention.
The electronic device of the present invention includes: one or more processors; a storage device, configured to store one or more programs, which when executed by the one or more processors, cause the one or more processors to implement a method for generating a model file according to an embodiment of the present invention.
The computer readable medium of the present invention has stored thereon a computer program which, when executed by a processor, implements a method of generating a model file of an embodiment of the present invention.
Referring now to FIG. 8, shown is a block diagram of a computer system 800 suitable for use in implementing an electronic device of an embodiment of the present invention. The electronic device shown in fig. 8 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 8, the computer system 800 includes a Central Processing Unit (CPU)801 that can perform various appropriate actions and processes in accordance with 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. In the RAM 803, various programs and data necessary for the operation of the computer system 800 are also stored. The CPU 801, ROM 802, and RAM 803 are connected to each other via a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
The following components are connected to the I/O interface 805: an input portion 806 including a keyboard, a mouse, and the like; an output section 807 including a signal such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 808 including a hard disk and the like; and a communication section 809 including a network interface card such as a LAN card, a modem, or the like. The communication section 809 performs communication processing via a network such as the internet. A drive 810 is also connected to the I/O interface 805 as necessary. A removable medium 811 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 810 as necessary, so that a computer program read out therefrom is mounted on the storage section 808 as necessary.
In particular, the processes described above with respect to the main step diagrams may be implemented as computer software programs, according to embodiments of the present disclosure. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program containing program code for performing the method illustrated in the main step diagram. 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 executes the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 801.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, 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), an optical fiber, 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 invention, 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. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
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 invention. 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 which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a function call module, a parsing storage module, and a traversal generation module. Where the names of these modules do not in some cases constitute a limitation of the module itself, for example, a function call module may also be described as a "module that calls an entry function, which when called, passes in input parameters.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: calling an entry function, and transmitting input parameters when the entry function is called; wherein the input parameters include target data and a model file name; analyzing the target data, and storing the analyzed object into the created class name file and the created class object file according to the object type; traversing the elements of the class object file, and generating a model file corresponding to the model file name according to the data type of the elements and the class name file and a set file format.
From the above description, it can be seen that the input parameters including the target data and the model file name are transmitted by calling the entry function, so as to automatically generate the model file according to the transmitted parameters, reduce the creation time of the model file, have high accuracy, and improve the development efficiency at the same time.
The product can execute the method provided by the embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (13)

1. A method for generating a model file, comprising:
calling an entry function, and transmitting input parameters when the entry function is called; wherein the input parameters include target data and a model file name;
analyzing the target data, and storing the analyzed object into the created class name file and the created class object file according to the object type;
traversing the elements of the class object file, and generating a model file corresponding to the model file name according to the data type of the elements and the class name file and a set file format.
2. The method of claim 1, wherein the class object file comprises a class name attribute and a class attribute;
the step of storing the analyzed object into the created class name file and the created class object file according to the object type includes:
if the object is not an array or a dictionary, adding the initialized temporary dictionary as the class attribute to the class object file;
if the object is an array, removing non-dictionary type data in the array, combining the removed data into a first new dictionary, traversing keys in the first new dictionary, and storing the first new dictionary into the created class name file and the created class object file according to the type of key values;
and if the object is a dictionary, traversing keys in the dictionary, and storing the dictionary to the created class name file and the created class object file according to the type of the key value.
3. The method of claim 2, wherein the input parameters further comprise: sub-model suffix name; storing the dictionary to the created class name file and the created class object file according to the key value type, wherein the method comprises the following steps:
if the key value type is null or a character string, taking the key as the key of the temporary dictionary, taking the value of the temporary dictionary as null or the character string correspondingly, and adding the temporary dictionary as the category attribute into the category object file;
if the key value type is a dictionary, splicing the key and the sub-model suffix name to obtain a first splicing character string, traversing whether the first splicing character string exists in the class name file, if so, adding a first identifier in the first splicing character string to obtain a first new splicing character string, and after traversing is finished, adding the first splicing character string or the first new splicing character string to the class name file;
and taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is the first splicing character string or the first new splicing character string, and the temporary dictionary is taken as the category attribute and added into the category object file.
4. The method of claim 2, wherein the input parameters further comprise: sub-model suffix name; storing the dictionary to the created class name file and the created class object file according to the key value type, wherein the method comprises the following steps:
if the key value type is an array, removing non-dictionary type data in the array, merging the removed data into a second new dictionary, and if the second new dictionary is empty, taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is a set character string;
if the second new dictionary is not empty, the key and the sub-model suffix name are spliced to obtain a second splicing character string, whether the second splicing character string exists in the class name file is traversed, if yes, a first identifier is added into the second splicing character string to obtain a second new splicing character string, and after traversal is completed, the second splicing character string or the second new splicing character string is added into the class name file;
and taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is the splicing of the second splicing character string or the second new splicing character string and the set character string, and the temporary dictionary is taken as the category attribute and added into the class object file.
5. The method of claim 2, wherein the input parameters further comprise: sub-model suffix name; storing the dictionary to the created class name file and the created class object file according to the key value type, wherein the method comprises the following steps:
if the key value type is other types, obtaining a class description character string, and if the class description character string contains an NSCFBoolean character string, taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is a Boolean character string; wherein the other types are types other than null, character strings, dictionaries, and arrays;
if the class description character string contains NSCFNumber character strings and is of a long type, taking the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is an integer character string;
and if the class description character string contains NSCFNumber character strings and is of a double type, using the key as the key of the temporary dictionary, wherein the value of the temporary dictionary is a double-precision character string.
6. The method of claim 1, wherein the model file comprises a model declaration file;
generating a model declaration file corresponding to the model file name according to a set file format, wherein the model declaration file comprises:
acquiring the category attribute of the current element of the class object file and the key of the category attribute, and declaring a first temporary character string;
traversing the keys of the category attributes and the elements of the keys, matching the current elements of the keys with set matching conditions, and assigning values to the first temporary character strings according to matching results;
and the splicing type definition character string and the assigned first temporary character string are written into a file to generate a model statement file.
7. The method of claim 6, wherein the matching condition comprises any one or more of:
whether the type of the value corresponding to the current element of the key is null, a character string, Boolean, double precision or an integer, whether the current element of the key starts with an array character string, and whether the class name file contains the current element.
8. The method of any of claims 1 to 7, wherein the model file comprises a model implementation file;
generating the model implementation file corresponding to the model file name according to a set file format, wherein the model implementation file comprises:
setting a value of a second temporary character string according to the type of the current element of the class object file;
initializing a third temporary character string, traversing keys in the category attribute in the category object file, and assigning a value to the third temporary character string under the condition that a current key starts with an array and the residual character string after intercepting the array of the current key is not 0;
after traversing is finished, updating the third temporary character string by combining the second temporary character string according to the length of the third temporary character string;
and the fourth splicing character string is written into a file to generate a model implementation file.
9. The method of any of claims 1 to 7, wherein the input parameters further comprise: a model file storage address; the method further comprises the following steps:
outputting the model file to a designated storage location; wherein the designated storage location is the model file storage address.
10. The method of claim 3, further comprising:
if the key value type is a dictionary, judging whether repeated keys exist in a parent dictionary of the current dictionary;
and if repeated keys exist, adding a second identifier in the corresponding key of the parent dictionary, and taking the key added with the second identifier as the corresponding key of the current dictionary.
11. An apparatus for generating a model file, comprising:
the function calling module is used for calling an entry function and transmitting input parameters when the entry function is called; wherein the input parameters include target data and a model file name;
the analysis storage module is used for analyzing the target data and storing the analyzed object to the created class name file and the created class object file according to the object type;
and the traversal generation module is used for traversing the elements of the class object file and generating a model file corresponding to the model file name according to the data type of the elements and the class name file and a set file format.
12. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-10.
13. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-10.
CN201910943856.5A 2019-09-30 2019-09-30 Method and device for generating model file Pending CN112579151A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910943856.5A CN112579151A (en) 2019-09-30 2019-09-30 Method and device for generating model file

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910943856.5A CN112579151A (en) 2019-09-30 2019-09-30 Method and device for generating model file

Publications (1)

Publication Number Publication Date
CN112579151A true CN112579151A (en) 2021-03-30

Family

ID=75116867

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910943856.5A Pending CN112579151A (en) 2019-09-30 2019-09-30 Method and device for generating model file

Country Status (1)

Country Link
CN (1) CN112579151A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114218171A (en) * 2021-12-22 2022-03-22 武汉斗鱼鱼乐网络科技有限公司 Convenient storage method, electronic equipment, storage medium and system
CN115374079A (en) * 2022-07-15 2022-11-22 清华大学 HDF5 format-based nuclear reaction database manufacturing method and device
CN117251416A (en) * 2023-11-10 2023-12-19 深圳软牛科技有限公司 File scanning method, device, computer equipment and storage medium

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114218171A (en) * 2021-12-22 2022-03-22 武汉斗鱼鱼乐网络科技有限公司 Convenient storage method, electronic equipment, storage medium and system
CN115374079A (en) * 2022-07-15 2022-11-22 清华大学 HDF5 format-based nuclear reaction database manufacturing method and device
CN117251416A (en) * 2023-11-10 2023-12-19 深圳软牛科技有限公司 File scanning method, device, computer equipment and storage medium
CN117251416B (en) * 2023-11-10 2024-03-29 深圳软牛科技集团股份有限公司 File scanning method, device, computer equipment and storage medium

Similar Documents

Publication Publication Date Title
CN110555030B (en) SQL sentence processing method and device
He et al. Model approach to grammatical evolution: deep-structured analyzing of model and representation
CN110543297B (en) Method and apparatus for generating source code
US11775269B2 (en) Generating a synchronous digital circuit from a source code construct defining a function call
CN112579151A (en) Method and device for generating model file
CN113238740B (en) Code generation method, code generation device, storage medium and electronic device
CN111125064B (en) Method and device for generating database schema definition statement
CN109002389B (en) Method and device for automatically testing page
CN111078230A (en) Code generation method and device
CN113419789A (en) Method and device for generating data model script
CN113419740A (en) Program data stream analysis method and device, electronic device and readable storage medium
CN113297081B (en) Execution method and device of continuous integrated pipeline
US8949713B1 (en) Version-specific request processing
CN112947941A (en) Method and device for adding exception handling code
CN113238739A (en) Plug-in development and data acquisition method, device, electronic equipment and medium
CN113032004B (en) Method, apparatus and program product for managing development jobs in a development environment
CN117251164A (en) Model code conversion method, device, equipment and storage medium
CN113536748A (en) Method and device for generating chart data
CN113760240B (en) Method and device for generating data model
CN110764768A (en) Method and device for mutual conversion between model object and JSON object
CN113138767B (en) Code language conversion method, device, electronic equipment and storage medium
CN114625373A (en) Application conversion method and device, electronic equipment and storage medium
US20160350090A1 (en) Information processing apparatus, method of compiling, and storage medium
CN113515285A (en) Method and device for generating real-time calculation logic data
CN111880775A (en) Multi-module layered architecture implementation method and device, electronic equipment and 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