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是轉(zhuǎn)換json格式的字典)
2.數(shù)組
數(shù)組其實和字典一樣带兜,只需將(dataWithJSONObject:dicFriends)參數(shù)刹衫,換成數(shù)組就可以了