JSON和Object互相转换是App开发中最常用的功能之一;
####MFSJSONEntity的特点:
####实体对象属性类型支持:
#安装 ####编译静态Framework
git clone https://github.com/maxfong/MFSJSONEntity.git
选择 lipoFramework Target 编译即可
####引用framework
#import <MFSJSONEntity/MFSJSONEntity.h>
#####使用framework需要Other Linker Flags添加-ObjC;
###CocoaPods
编辑Pofile
pod 'MFSJSONEntity', '1.0.1'
安装
pod install
更多关于CocoaPods.
#使用
###Object -> Dictionary(当前类属性键值对)
Person *person = Person.new;
person.name = @"max";
person.age = 99;
NSDictionary *personDict = [person propertyDictionary];
NSLog(@"Person:%@", personDict);
###Dictionary -> Object(支持多层嵌套)
NSString *JSONString = @"{\"name\":\"max\",\"age\":98}";
NSData *JSONData = [JSONString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingAllowFragments error:nil];
Person *obj = [Person objectWithDictionary:dictionary];
NSLog(@"person:%@, name:%@, age:%ld", obj, obj.name, obj.age);
###属性列表(可自定义父类)
NSArray *propertys = [Person propertyNames];
NSLog(@"Person propertys:%@", propertys);
#其他 如果您发现任何问题或有啥建议,请发个issues,谢谢;
#许可证
MFSJSONEntity 适用于MIT许可证。有关更多信息,请参阅LICENSE文件。