Mac iOS Json operation Model to JSON, iosjson

Source: Internet
Author: User

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. hImport 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]);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.