工程里面会遇到一些关于字典包数组对象的情况 直接放进去是不行的 需要进行转换的方法
NSMutableDictionary*dictionary = [[NSMutableDictionaryalloc]init];
[dictionarysetValue:@"hello"forKey:@"one"];
[dictionarysetValue:@"world"forKey:@"two"];
NSArray*arry=[NSArrayarrayWithObjects:@"001",@"002",@"003",nil];
[dictionarysetValue:arryforKey:@"three"];
NSData*data=[NSJSONSerializationdataWithJSONObject:dictionaryoptions:NSJSONWritingPrettyPrintederror:nil];
NSString*jsonStr=[[NSStringalloc]initWithData:dataencoding:NSUTF8StringEncoding];
NSLog(@"jsonStr==%@",jsonStr);
输出结果为:
str=={
"one" : "hello",
"two" : "world",
"three" : [
"001",
"002",
"003"
]
}
网友评论