The JSON string is deserialized into an object under iOS. It's more common in formal projects. For example, the following several often use open source libraries. You can choose one of the following according to your preference:
1.?jsonmodel:?https://github.com/icanzilb/jsonmodel
2.?mjextension:?https://github.com/codermjlee/mjextension
3.? mantle:? Https://github.com/Mantle/Mantle
The Jsonmodel of anarray element is defined by the same @protocol as the class name of the element model.
{ "order_id": 104, "Total_price": 103.45, "Products": [ { "id": "123", "name": "Product #1", "Price": 12.95 }, { "id": "137", "name": "Product #2", "price": 82.95 } ]}
@protocol productmodel@end@interface Productmodel:jsonmodel@property (assign, nonatomic) int id; @property (strong, nonatomic) nsstring* name; @property (assign, nonatomic) float price; @end @implementation Productmodel@end@interface Ordermodel:jsonmodel@property (assign, nonatomic) int order_id; @property (assign, nonatomic) float total_price;@ Property (Strong, Nonatomic) Nsarray<productmodel, convertondemand>* products; @end @implementation Ordermodel@end
mjextension is known as "the world's fastest conversion, using the simplest and most convenient dictionary to model framework", interested in can see the detailed instructions under GitHub.
JSON deserialization of open source libraries under iOS