iOS_Json字符串转字典、字典转成Json字符串
来源:互联网 发布:程序员岗位职责说明书 编辑:程序博客网 时间:2024/06/06 10:05
开发过程中经常会遇到json转化问题。以下就自己的代码做个笔记:
#pragma mark - json操作/** * 把格式化的JSON格式的字符串转换成字典 * * @param jsonString jsonString JSON格式的字符串 * * @return 返回字典 */+ (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格式的对象(字典)转化成json字符串 * * @param jsonObject json对象 * * @return 带json格式的字符串 */+ (NSString *)jsonStringWithObject:(id)jsonObject{ // 将字典或者数组转化为JSON串 NSError *error = nil; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:&error]; NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; if ([jsonString length] > 0 && error == nil){ return jsonString; }else{ return nil; }}
0 1
- iOS_Json字符串转字典、字典转成Json字符串
- iOS_Json字符串转字典、字典转成Json字符串
- json字符串转成字典
- iOS 将字典转成json格式字符串
- 字典转json字符串
- 字典转成字符串iOS
- json字符串转字典,字典转json字符串
- iOS 字典转JSON字符串
- C#Json字符串转字典
- //普通字符串转JSON字符串转字典
- json字符串转为字典
- 字典转为Json字符串
- iOS数组和字典转Json字符串
- 数组、字典转json格式字符串
- iOS字符串转字典(json)
- iOS-JSON字符串转NSDictionary / 字典转JSON字符串
- 字典转化为 json 字符串
- JSON字符串转化为字典
- 开学季!MathType 6.9 序列号限时大促销进行中!
- oracle contains函数 全文检索
- 【笔试】28、二进制中1的个数
- 用消息队列模拟生产者消费者模型
- Android中的Intent(意图)的使用
- iOS_Json字符串转字典、字典转成Json字符串
- Redis HASH 操作类型封装
- ReactiveCocoa Documents 翻译(基于版本V2.5)
- Android Studio 9 patch 编译错误
- FTP命令字和响应码
- MongoDB 去重 分组(针对于某个field 或者 组合项的去重)
- LeetCode题解:Two Sum
- HDU2421Deciphering Password(数论&质因数分解)
- 【算法】【动态规划】Coin Exchange