·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> JSONModel

JSONModel

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23
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);