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"
]
}