在ios7中解析JSON数组
我有以下JSON代码:在ios7中解析JSON数组,ios,json,parsing,Ios,Json,Parsing,我有以下JSON代码: [ { "descrizione": "Risotto Giallo con Stinco", "prezzo": null }, { "descrizione": "Orecchietta al ragu bolognese", "prezzo": null }, { "descrizione": "Penne ai gamberi", "prezzo": null } ] 要在文本视图中打
[
{
"descrizione": "Risotto Giallo con Stinco",
"prezzo": null
},
{
"descrizione": "Orecchietta al ragu bolognese",
"prezzo": null
},
{
"descrizione": "Penne ai gamberi",
"prezzo": null
}
]
要在文本视图中打印,因此我编写了以下代码:
self.MenuGiorno.text = [self.MenuGiorno.text stringByAppendingString:[NSString stringWithFormat:@"%@",jsonArray1]];
当然,通过这种方式,我可以在文本视图中看到完整的代码,而无需对其进行解析
我如何指定只打印“Descriptione”和“prezzo”?不要介意意大利语,最后两个是我必须用来填充文本视图的标识符。有人有主意吗?jasonArray1是一系列字典。首先必须访问数组元素,因为只有一个元素,字典。然后按键名访问字典项
NSString *str = jsonArray1[0][@"descrizione"];
或者更详细地说:
NSArray *fistArrayElement = [jsonArray1 firstObject];
NSString *str = [fistArrayElement objectAtIndex:@"descrizione"];
你有一系列字典。从数组中获取所需的字典,然后从字典中获取所需的值。请为我编写一个相关示例,好吗?使用
NSJSONSerialization
+(id)JSONObjectWithData:(NSData*)数据选项:(NSJSONReadingOptions)opt error:(NSError**)error
。然后按键访问项目:attar[0][@“keyName”]
No。这太琐碎了。做一些研究和搜索。从NSArray
和NSDiitionary
@Zaph的文档开始-查看OP的代码。他们已经有了JSON中的数组。通过这种方式,我必须在textview中插入firstArrayElement吗?我是对的吗?我试着这样做:for(I=0;I)