JSON和Object互转是App开发中最常用的功能之一;
- NSObject的类别;
- 比较轻量;
- 转换功能全;
- NSString
- NSArray
- NSDictionary
- NSNull
- 值基本类型
git clone https://github.com/maxfong/MFSJSONEntity.git
选择 lipoFramework Target 编译即可
#import <MFSJSONEntity/MFSJSONEntity.h>
编辑Pofile
pod 'MFSJSONEntity', '1.0.6'
安装
pod install
更多关于CocoaPods.
Person *person = Person.new;
person.name = @"max";
person.age = 99;
NSDictionary *personDict = [person propertyDictionary];
NSLog(@"Person:%@", personDict);
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 is available under the MIT license. See the LICENSE file for more info.