JSONModel

1 //仅仅声明属性的类,称为实体类(模型类)
2 //Student.h中声明属性
3 @property(strong,nonatomic)NSString *name;
4 @property(assign,nonatomic)int age;
5 @property(strong,nonatomic)NSArray *array;
//导入JSONModel第三方库
//在AppDelegate.h中引入学生类的头文件
//在AppDelegate.m要写的代码
//JsonModel作用为将数据转换成模型
NSString *str=@"{"name":"zhangsan","age":20,"array":["a"]}";
//用数据初始化对象
Student *stu=[[Student alloc]initWithString:str error:nil];
NSLog(@"%@",stu);
NSLog(@"%@",stu.toDictionary);
NSLog(@"%@",stu.toJSONString);
原文地址:https://www.cnblogs.com/y16879w/p/4466630.html