1.字典
NSMutableDictionary *dicFriends = [[NSMutableDictionary alloc] init];
[dicFriends setObject:friends forKey:@"usernames"];
NSData *dataFriends = [NSJSONSerialization dataWithJSONObject:dicFriends options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonString = [[NSString alloc] initWithData:dataFriends
encoding:NSUTF8StringEncoding];
(ps usernames 是字段,jsonString是转换json格式的字典)
2.数组
数组其实和字典一样,只需将(dataWithJSONObject:dicFriends)参数,换成数组就可以了