iOS对象(字典或数组)转化为JSon字符串
2016-12-15 19:02
519 查看
转自:http://blog.csdn.net/dlg1992/article/details/49176843
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
[dictionary setValue:@"hello" forKey:@"one"];
[dictionary setValue:@"world" forKey:@"two"];
NSArray *arry=[NSArray arrayWithObjects:@"001",@"002",@"003", nil];
[dictionary setValue:arry forKey:@"three"];
NSData *data=[NSJSONSerializationdataWithJSONObject:dictionaryoptions:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonStr=[[NSString alloc]initWithData:dataencoding:NSUTF8StringEncoding];
NSLog(@"jsonStr==%@",jsonStr);
输出结果为:
str=={
"one" : "hello",
"two" : "world",
"three" : [
"001",
"002",
"003"
]
}
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
[dictionary setValue:@"hello" forKey:@"one"];
[dictionary setValue:@"world" forKey:@"two"];
NSArray *arry=[NSArray arrayWithObjects:@"001",@"002",@"003", nil];
[dictionary setValue:arry forKey:@"three"];
NSData *data=[NSJSONSerializationdataWithJSONObject:dictionaryoptions:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonStr=[[NSString alloc]initWithData:dataencoding:NSUTF8StringEncoding];
NSLog(@"jsonStr==%@",jsonStr);
输出结果为:
str=={
"one" : "hello",
"two" : "world",
"three" : [
"001",
"002",
"003"
]
}
相关文章推荐
- iOS对象(字典或数组)转化为JSon字符串
- iOS对象(字典或数组)转化为JSon字符串
- iOS对象(数组)转化为JSon字符串
- iOS对象(字典或数组)转化为JSon…
- [iOS]将含有NSData数据的数组转化为json字符串报错:reason: 'Invalid type in JSON write (NSConcreteMutableData)
- ios mjextension 字典数组转模型数组并转化为jsonString
- iOS数组、字典与json字符串的转换
- Java 对象,数组 与 JSON 字符串 相互转化
- iOS数组和字典转Json字符串
- object转化成json,json格式字符串转字典,数组或字典转为json串
- JS 将变量 转化为字符串的方法, 适用于所有类型,数组, JSON对象,函数和基本类型等
- 后台将对象转换为json格式,前台js解析json数据,将字符串转化为数组
- iOS字典对象和数组对象转成json
- post发送JSON数据(字符串、数组、字典、自定义对象)给服务器
- iOS json格式的字符串转字典或数组
- Json字符串与字典对象的相互转化
- js爬虫拿到的字符串数据转化成数组再转化成json对象
- ios 把数组转化为json再转化为字符串、再去除空格和分隔符“\n”
- iOS-OC-把JSON字符串转化为字典
- json对象转化字符串、数组