Objective-c 自定对象 转 JSON
来源:互联网 发布:科比安东尼西决数据 编辑:程序博客网 时间:2024/06/05 17:18
#pragma mark - NSObject to JSON -
static NSDateFormatter *reverseFormatter;
- (NSDateFormatter *)getReverseDateFormatter {
if (!reverseFormatter) {
NSLocale *locale = [[NSLocalealloc] initWithLocaleIdentifier:@"en_US_POSIX"];
reverseFormatter = [[NSDateFormatteralloc] init];
[reverseFormattersetDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
[reverseFormatter setLocale:locale];
}
returnreverseFormatter;
}
- (NSDictionary *)dictionaryWithPropertiesOfObject:(id)obj {
NSMutableDictionary *dict = [NSMutableDictionarydictionary];
unsigned count;
objc_property_t *properties =class_copyPropertyList([obj class], &count);
for (int i =0; i < count; i++) {
NSString *key = [NSStringstringWithUTF8String:property_getName(properties[i])];
id object = [obj valueForKey:key];
if (object) {
if ([object isKindOfClass:[NSArray class]]) {
NSMutableArray *subObj = [NSMutableArrayarray];
for (id oin object) {
[subObj addObject:[selfdictionaryWithPropertiesOfObject:o]];
}
dict[key] = subObj;
}
else if ([object isKindOfClass:[NSStringclass]]) {
dict[key] = object;
} else if ([object isKindOfClass:[NSDateclass]]) {
dict[key] = [[selfgetReverseDateFormatter] stringFromDate:(NSDate *) object];
} else if ([object isKindOfClass:[NSNumberclass]]) {
dict[key] = object;
} else if ([[object class] isSubclassOfClass:[NSObjectclass]]) {
dict[key] = [selfdictionaryWithPropertiesOfObject:object];
}
}
}
return dict;
}
- Objective-c 自定对象 转 JSON
- Objective - c JsonKit 进行json转对象 对象转json数据 & Jastor json数据转为对象
- JSON in objective c
- objective-c-json-js
- objective-c JSON学习
- Objective-C Json 使用
- objective-c post json
- Objective-C JSON操作
- kafka自定定义对象实现
- ArrayList集合存储自定对象
- objective-c对象初始化
- Objective-C对象模型
- Objective-C ---分布式对象
- objective-c 复制对象
- Objective-C对象模型
- objective C 对象模型
- Objective-C对象初始化
- Objective C面向对象
- 使用AndroidStudio将工具库打成jar包和aar包
- The method process(ItemDetailInfo, Task) of type ItemRuKuUtils must override a superclass method的解决方
- CMD循环
- Netty源码解读Promise
- HDU-1863-畅通工程(最小生成树,prim)
- Objective-c 自定对象 转 JSON
- 《编程珠玑》——第一章习题
- crt连接不上Linux虚拟机
- java设计模式01
- Docker网络之一:Docker 默认网络
- myrocks 的 pk 的生成原理(k/v)
- 打开r40平台Anroid6.0下的AP6212A1版本的WIFI(兼容配置)(分色排版)
- 安卓拍照及图片裁剪(6.0以上权限处理及7.0以上文件管理)
- Hibernate之Criteria标准化对象查询小Demo