JSON的序列化,代码示例:

    NSDictionary *dic = @{@"name":@"zhuzhu", @"age":@};
if (![NSJSONSerialization isValidJSONObject:dic]) {
NSLog(@"该对象不支持转换");
return;
}
/**
- Top level object is an NSArray or NSDictionary
- All objects are NSString, NSNumber, NSArray, NSDictionary, or NSNull
- All dictionary keys are NSStrings
- NSNumbers are not NaN or infinity
*/
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:kNilOptions error:nil];
NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"%@", jsonStr);

JSON的反序列化,代码示例:

NSDictionary *dic = @{@"name":@"zhuzhu", @"age":@};
if (![NSJSONSerialization isValidJSONObject:dic]) {
NSLog(@"该对象不支持转换");
return;
}
/**
- Top level object is an NSArray or NSDictionary
- All objects are NSString, NSNumber, NSArray, NSDictionary, or NSNull
- All dictionary keys are NSStrings
- NSNumbers are not NaN or infinity
*/
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:kNilOptions error:nil];
  // 反序列的代码
NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil]; NSLog(@"dic=%@", jsonDic);

最新文章

  1. 远程ssh登陆时报错:/bin/bash: Permission denied
  2. kafka_2.11-0.8.2.2的搭建
  3. mysql事件调度器定时删除binlog
  4. OpenCV -- 获取轮廓照片
  5. asp.net mvc jqgrid 同一个页面查询不同的表,jqgrid显示不同表的表头和数据并且分页
  6. c#转码解码
  7. 11g的alert日志路径
  8. 完整具体解释GCD系列(二)dispatch_after;dispatch_apply;dispatch_once
  9. # Instrument Time Profiler教程之Time Profiler
  10. CentOS6.x服务器OpenSSH平滑7.3p版本——拒绝服务器漏洞攻击
  11. hql语句中的select字句和from 字句
  12. [Python] timeit测试代码运行效率
  13. Docker Compose 配置文件常用指令
  14. P4774 [NOI2018]屠龙勇士
  15. kali虚拟机安装后操作[配置ssh,安装vmtools,更新源]
  16. 配置tomcat报错: Unknown version of Tomcat was specified.
  17. Ubuntu 14.04 下安装 TFTP 艰辛之路【转】
  18. SCP远程拷贝命令
  19. Hadoop源码解析 1 --- Hadoop工程包架构解析
  20. 题解【luogu4145 上帝造题的七分钟2(花神游历各国)】

热门文章

  1. 对象流,它们是一对高级流,负责即将java对象与字节之间在读写的过程中进行转换。 * java.io.ObjectOutputStream * java.io.ObjectInputStream
  2. 【实习第二天】odoo开发基础(二)
  3. 模拟超市付款 (if 多分支结构)
  4. 更改 undo_retention 时,Lob retention 不更改 (Doc ID 563470.1)
  5. Linux—修改文件权限、文件拥有者以及文件所在组
  6. Internet Download Manager是什么?
  7. 二、ITK例子-jpg图像读写
  8. Day12- Python基础12 线程、GIL、Lock锁、RLock锁、Semaphore锁、同步条件event
  9. 验证登录的前世今生:session、cookie
  10. 挑战编程 uva100 3n+1