iOS对象(字典或数组)转化为JSon字符串
2017-11-03 09:30
363 查看
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=[NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonStr=[[NSString alloc]initWithData:dataencoding:NSUTF8StringEncoding];
NSLog(@"jsonStr==%@",jsonStr);
输出结果为:
str=={
"one" : "hello",
"two" : "world",
"three" : [
"001",
"002",
"003"
]
}
[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=[NSJSONSerialization dataWithJSONObject:dictionary options: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…
- Java 对象,数组 与 JSON 字符串 相互转化
- json对象转化字符串、数组
- post发送JSON数据(字符串、数组、字典、自定义对象)给服务器
- iOS字典对象和数组对象转成json
- JS 将变量 转化为字符串的方法, 适用于所有类型,数组, JSON对象,函数和基本类型等
- iOS json格式的字符串转字典或数组
- 数组、字典转化为json字符串
- [iOS]将含有NSData数据的数组转化为json字符串报错:reason: 'Invalid type in JSON write (NSConcreteMutableData)
- ios 把数组转化为json再转化为字符串、再去除空格和分隔符“\n”
- object转化成json,json格式字符串转字典,数组或字典转为json串
- eval函数就是JavaScript用来解释JSON字符串的,把字符串转化为对象、数组、函数或者其它。
- iOS-OC-把JSON字符串转化为字典
- Json字符串与字典对象的相互转化
- iOS数组和字典转Json字符串
- 前台的js对象数组传到后台处理。在前台把js对象数组转化为json字符串,在后台把json字符串解析为List<>
- 字典、数组和json字符串的相互转化