我想创建一个 JSON 字符串,如下所示
{
"veneue": {
"clientId": "b",
"name": "d",
"tagline": "f",
"phone": "b",
"address": "d",
"city": "f",
"state": "b",
"zip": "d",
"twitter": "f",
"license": "d",
"imagePath": "f",
"pickupLocation": "b"
},
"drinks": [
{
"type": "d",
"name": "f",
"servingTable": {
"servingSize": "b",
"price": "d"
}
},
{
"type": "d",
"name": "f",
"servingTable": {
"servingSize": "b",
"price": "d"
}
}
]
}
这是我的模型
JSON 字符串应包含两个 JSONObject venue, drinks
,.
Venue 有下面列出的子对象,如venueDictionary。其中作为 Drinks 是一个模型的数组DrinkClass
NSDictionary *venueDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@"name" ,@"xx"//[self.nameVenue text],
@"tagLine",@"xx"//[self.taglineVenue text],
@"phone" ,@"xx"//[self.phoneVenue text],
@"addres" ,@"xx"//[self.addressVenue text],
@"city" ,@"xx"//[self.cityVenue text],
@"state" ,@"xx"//[self.stateVenue text],
@"zip" ,@"xx"//[self.zipVenue text],
@"twitter",@"xx"//[self.twitterVenue text],
@"license",@"xx"//[self.licenseVenue text],
@"pickUpLocation",@"xx"//[self.pickUpVenue text],
@"imagePath",randomImageName,
nil];
arrayDrinks = [[NSMutableArray alloc] init]; //SUPPOSE THIS IS DRINK ARRAY
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@"venue", venueDictionary,
@"drinks",
nil];
1-如何将它添加到@"drinks" 以创建 JSON 如上所述,其次我正在使用 SBJSONWriter ,如何使用 JSONDictionary 创建字符串。
//SBJsonWriter *writer = [[SBJsonWriter alloc] init];