Mac iOS Json operation Model to JSON, iosjson
In the mobile Internet era, json has become the mainstream data exchange format. It is essential for developers to easily and quickly create, convert, and transmit json files. Fortunately, we live in the open-source era, and many features do not need to be reproduced. Today I recommend an Open Source json processing library. Project address: https://github.com/icanzilb/jsonmodeli can output the following json:
In fact, writing directly is also very easy, but it is very troublesome to use objects for later maintenance. Therefore, I abstracted the above json into a class. As follows:
JSContentsModel. h
'''
Import
JSONModel. h
Import
RFIConModel. h
@ Interface JSContentsModel: JSONModel
@ Property (strong, nonatomic) NSArray * Images;
@ End
'''
After inheriting the JSONModel, The JSContentsModel can freely convert json. Images is the abstraction of the images array in json. Below, I will abstract the array content.
RFIconModel
'''
@ Protocol RFIConModel @ end
@ Interface RFIConModel: JSONModel
@ Property (nonatomic, strong) NSString * filename;
@ Property (nonatomic) NSNumber * imageWidth;
@ Property (nonatomic) NSNumber * imageHeight;
@ Property (nonatomic) NSString * scale;
@ Property (nonatomic) NSString * comments;
@ End
'''
The RFIconModel object is an abstraction of the images array content. This completes all the work on the json file. It's easy and quick. The test code is as follows:
JSONModelArray * jImages=[[JSONModelArray alloc] initWithArray:images modelClass:[RFIConModel class]]; JSContentsModel * oneModel=[[JSContentsModel alloc] init]; oneModel.images=images; NSLog(@"%@",[oneModel toJSONString]);