You can also process Json yourself, convert json into a dictionary, and then use the dictionary to assign values to the properties of the object (traverse the properties of the object and assign values)
As Blake said, first convert Json into a dictionary, and then convert the dictionary into a model. Regarding dictionary conversion, I just wrote an article a few days ago on the underlying principles of how the MJExtension framework converts a dictionary into a model. You can take a look at it. http: //weibo.com/p/1001603912111561547915 Because it is mainly implemented through Runtime, you need to understand the basics of Runtime first
To convert json into classes, you need to consider the following two issues 1. How to generate beautiful class types 2. What to do if the shape of each map in the array is different (usually it may mean inheritance
However, the second point is the knowledge implicit in the semantics that is difficult to obtain from a json.
There is an Xcode plug-in that can achieve similar functions, called ESJsonFormat ● GitHub address It can automatically create classes and attributes based on the content of JSON strings. For details, please see the DEMO in GitHub.
The following reference
MJExtension
JSONModel
You can also process Json yourself, convert json into a dictionary, and then use the dictionary to assign values to the properties of the object (traverse the properties of the object and assign values)
As Blake said, first convert Json into a dictionary, and then convert the dictionary into a model. Regarding dictionary conversion, I just wrote an article a few days ago on the underlying principles of how the MJExtension framework converts a dictionary into a model. You can take a look at it. http: //weibo.com/p/1001603912111561547915
Because it is mainly implemented through Runtime, you need to understand the basics of Runtime first
https://github.com/EnjoySR/ESJsonFormat-Xcode You can try this
To convert json into classes, you need to consider the following two issues
1. How to generate beautiful class types
2. What to do if the shape of each map in the array is different (usually it may mean inheritance
However, the second point is the knowledge implicit in the semantics that is difficult to obtain from a json.
I estimate that most people use third parties
There is an Xcode plug-in that can achieve similar functions, called
ESJsonFormat
● GitHub addressIt can automatically create classes and attributes based on the content of JSON strings.
For details, please see the DEMO in GitHub.
xcode uses ESJsonFormat and IDEA uses GsonFormat.