date: 2015-12-10 09:24:16
- A fast, convenient and nonintrusive conversion between JSON and model.
- 转换速度快、使用简单方便的字典转模型框架
- MJExtension是一套字典和模型之间互相转换的超轻量级框架
- JSON –> Model、Core Data Model
- JSONString –> Model、Core Data Model
- Model、Core Data Model –> JSON
- JSON Array –> Model Array、Core Data Model Array
- JSONString –> Model Array、Core Data Model Array
- Model Array、Core Data Model Array –> JSON Array
- Coding all properties of model in one line code.
- 只需要一行代码,就能实现模型的所有属性进行Coding(归档和解档)
It include
1 2 3 4 5 6 7 8
|
MJExtension.h MJConst.h MJConst.m MJFoundation.h MJFoundation.m MJProperty.h MJProperty.m MJType.h MJType.m NSObject+MJCoding.h NSObject+MJCoding.m NSObject+MJProperty.h NSObject+MJProperty.m NSObject+MJKeyValue.h NSObject+MJKeyValue.m
|
examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
JSON -> Model
typedef enum { SexMale, SexFemale } Sex;
/***********************************************/
NSDictionary *dict = // // };
// JSON -> User User *user = [User mj_objectWithKeyValues:dict];
NSLog( // name=Jack, icon=lufy.png, age=20, height=1.550000, money=100.9, sex=1
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
Model contains model
/***********************************************/
NSDictionary *dict = }, } } };
// JSON -> Status Status *status = [Status mj_objectWithKeyValues:dict];
NSString *text = status.text; NSString *name = status.user.name; NSString *icon = status.user.icon; NSLog( // text=Agree!Nice weather!, name=Jack, icon=lufy.png
NSString *text2 = status.retweetedStatus.text; NSString *name2 = status.retweetedStatus.user.name; NSString *icon2 = status.retweetedStatus.user.icon; NSLog( // text2=Nice weather!, name2=Rose, icon2=nami.png
|
更多例子和下载请见: https://github.com/Qianxiaomu/MJExtension
近期评论