iOS JSON、NSDictionary互转
#import "myCode.h"
@implementation myCode
/*!
* @brief 把格式化的JSON格式的字符串转换成字典
* @param 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;
}
+ (NSString*)dictionaryToJson:(NSDictionary *)dic
{
NSError *parseError = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
@end
iOS JSON、NSDictionary互转的更多相关文章
- IOS 字典模型互转框架 MJExtension
IOS 字典模型互转框架 MJExtension 能做什么? MJExtension是一套字典和模型之间互相转换的超轻量级框架 MJExtension能完成的功能 字典(JSON) --> ...
- iOS - JSON 数据解析
iOS - JSON 数据解析 前言 NS_CLASS_AVAILABLE(10_7, 5_0) @interface NSJSONSerialization : NSObject @availab ...
- iOS Json转换模型库:YYModel
iOS Json转换模型库:YYModel 其实在研究这个库之前,市面上已经有很多类似的模型序列化成JSON及反序列化库(如Mantle.MJExtension)了,推荐他只是因为他高端的性能和容 ...
- DataTable 和Json 字符串互转
#region DataTable 转换为Json字符串实例方法 /// <summary> /// GetClassTypeJosn 的摘要说明 /// </summary> ...
- iOS JSON解析
解析json成dic对象 -(void)fetchedData:(NSData*)responseData {//parse out the json dataNSError* error; NSDi ...
- C#中另辟蹊径解决JSON / XML互转的问题
C#中另辟蹊径解决JSON / XML互转的问题 最近在一个POC的项目中要用到JSON和XML的相互转换, 虽然我知道很多类库如JSON.NET具备这种功能, 但是我还是另辟蹊径的使用Spider ...
- 二:C#对象、集合、DataTable与Json内容互转示例;
导航目录: Newtonsoft.Json 概述 一:Newtonsoft.Json 支持序列化与反序列化的.net 对象类型: 二:C#对象.集合.DataTable与Json内容互转示例: ...
- struct2json -- C结构体与 JSON 快速互转库V1.0发布
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/zhutianlong/article/d ...
- iOS JSON NSString Convert to NSDictionary
NSString *str = @"{\"info\":{\"body\":\"这个里面是是测试代码,里面有二个图片<!--img#0 ...
随机推荐
- Caffe学习
将binaryproto转为npy import caffe % suppose caffe is already in the path of Python import numpy as np i ...
- 三、基于hadoop的nginx访问日志分析--计算时刻pv
代码: # cat pv_hour.py #!/usr/bin/env python # coding=utf-8 from mrjob.job import MRJob from nginx_acc ...
- weblogic安全漫谈
今天,我来与大家探讨一下关于weblogic的话题 在进入内网后,如图: 当我们看到7001时,我们就可以测试weblogic反序列化漏洞,如图: 证明,漏洞存在,查看一下权限,如图: 理论上,我们可 ...
- 第一章 Part 1/2 Git 一览
虽然这个系列的文章主要关注的是Github,然而首先了解下Git的基本概念和名词也是非常有帮助的. 工作目录(Working Directory) 工作目录是你个人计算机上的一个目录.在该目录下,每一 ...
- 图解TCP/IP→第2章基础知识
####TCP.IP背景**关键词:ARPANET,UNIX,分组交换技术,*ARPANET(阿帕网),也是全球互联网的鼻祖.阿帕网的成功也充分证明了基于分组交换技术的通信方法的可行性.*20世纪70 ...
- JavaMail: SSL vs TLS vs STARTTLS
SSL vs TLS vs STARTTLS There's often quite a bit of confusion around the different terms SSL, TLS an ...
- 读取图像,LUT以及计算耗时
使用LUT(lookup table)检索表的方法,提高color reduce时对像素读取的速度. 实现对Mat对象中数据的读取,并计算color reduce的速度. 方法一:使用Mat的ptr( ...
- MongoDB安装配置示例
参考 http://www.runoob.com/mongodb/mongodb-window-install.html http://www.cnblogs.com/lecaf/archive/20 ...
- Qtp常见问题
(1)Qtp不能识别对象 插件加载错误 IE内未加载BHOManager加载项
- python模块引用问题(比较杂乱,懒得整理)
1 在stackoverflows摘抄 If the import module in the same dir, use e.g: from . import core If the import ...