- NSMutableDictionary *dictionary3 = [[NSMutableDictionary alloc] init];
- [dictionary3 setValue:@"Anthony3" forKey:@"First Name"];
- [dictionary3 setValue:@"Robbins3" forKey:@"Last Name"];
- NSMutableDictionary *dictionary2 = [[NSMutableDictionary alloc] init];
- [dictionary2 setValue:@"Anthony2" forKey:@"First Name"];
- [dictionary2 setValue:@"Robbins2" forKey:@"Last Name"];
- NSMutableArray * items = [[NSMutableArray alloc]init ];
- [items addObject:dictionary2];
- [items addObject:dictionary3];
- NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
- [dictionary setValue:@"Anthony" forKey:@"First Name"];
- [dictionary setValue:@"Robbins" forKey:@"Last Name"];
- [dictionary setValue:items forKey:@"items"];
- NSError *error = nil;
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary
- options:NSJSONWritingPrettyPrinted
- error:&error];
- if (error){
- NSLog(@"error");
- }
- NSString * param = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
- NSLog(param);
objective-c json 數據組裝
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.