iOS 系统自带JSON转字典 字典转JSON
来源:互联网 发布:淘宝小视频怎么上传 编辑:程序博客网 时间:2024/05/17 05:14
/*!
* @brief 把格式化的JSON格式的字符串转换成字典
* @param jsonString JSON格式的字符串
* @return 返回字典
*/
json格式字符串转字典:
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
if (jsonString == nil) {
return nil;
}
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *err;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers
error:&err];
if(err) {
NSLog(@"json解析失败:%@",err);
return nil;
}
return dic;
}
字典转json格式字符串:
+ (NSString*)dictionaryToJson:(NSDictionary *)dic
{
NSError *parseError = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
NSJSONWritingPrettyPrinted 是有换位符的。
如果NSJSONWritingPrettyPrinted 是nil 的话 返回的数据是没有 换位符的
原文链接:http://www.jianshu.com/p/6cca93f195b0
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
- iOS 系统自带JSON转字典 字典转JSON
- iOS JSON转字典
- iOS开发-字典转json
- iOS中 字典转Json
- iOS 字典转JSON字符串
- iOS 数组/字典转json
- json 转字典 字典转json
- json转字典
- 字典转json字符串
- 字典转json
- 数组 字典转Json
- IOS 字典转json 解决全角问题
- iOS开发笔记-json转字典
- ios字典与数组转JSon
- iOS数组和字典转Json字符串
- iOS字典转json 包含字段nsstring
- IOS 数组/字典转json串
- iOS字符串转字典(json)
- 聊聊职场那些事儿(转)
- Python学习笔记(数字)
- Dubbo源码分析(五)ExtensionLoader
- T-SQL Part XI: Login Failed 18456 以及修改Authentication Mode
- leetcode #153 in cpp
- iOS 系统自带JSON转字典 字典转JSON
- 定时任务cron
- Microsoft Azure IoT Hub应用 – 第一部分:向云端发送数据
- NSDate相关处理,获取当前时间戳,获取本地时间,获取星期 iOS新手笔记
- fmt标签的格式化日期使用
- git 迁移至 svn
- Java多线程 之 临界区、ThreadLocal(十)
- springMVC_02_为什么会出现
- 分布式一致性的paxos算法