iOS对象(字典或数组)转化为JSon…
2017-04-06 10:06
113 查看
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"
]
}
= [[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"
]
}
相关文章推荐
- iOS对象(字典或数组)转化为JSon字符串
- iOS对象(字典或数组)转化为JSon字符串
- iOS对象(字典或数组)转化为JSon字符串
- iOS对象(数组)转化为JSon字符串
- ios mjextension 字典数组转模型数组并转化为jsonString
- iOS字典对象和数组对象转成json
- 将JSON对象转化为数组对象
- iOS Json和对象互转(反射支持对象嵌套的复杂对象类型,支持基本数据类型和NSDate属性转化)
- 后台将对象转换为json格式,前台js解析json数据,将字符串转化为数组
- 字典、数组、JSON之间的转化小demo
- 在js中循环输出php数组(传值的时候,数组转化为json,这样你可以遍历json对象。)
- 前台的js对象数组传到后台处理。在前台把js对象数组转化为json字符串,在后台把json字符串解析为List<>
- .net Mvc Controller 接收 Json/post方式 数组 字典 类型 复杂对象
- JS将Array数组转化为轻量级JSON对象
- iOS 对象信息保存、转化JSON、JSON生成对象的模型方案记录
- 对前台传过来的json对象或数组进行转化
- iOS:把对象直接转化成NSDictionary或JSON
- JSONString 与 JSONData 与字典或者数组互相转化
- iOS: 把对象直接转化成NSDictionary或JSON
- java集合或对象转化为json数组或者对象的方法