【发布时间】:2012-05-15 13:46:22
【问题描述】:
我有this JSON 树,我需要按类别键对数组进行分组。 (在这个例子中,“”、“1”、“2”、“3”和“serf”是类别的值名称。)我正在使用 NSJSONSerialization 序列化 JSON,但无法按照我想要的方式解析它。这是我的一些代码:
NSData *data2=[NSData dataWithContentsOfURL:url2];
result2=[NSJSONSerialization JSONObjectWithData: data2
options: NSJSONReadingMutableContainers
error: nil];
NSLog(@"button data: %@", result2);
for (NSDictionary *strh in [result2 objectForKey:@"template"]) {
//the json struct above is called result2 here
//now i need to parse any category with their names..
}
相关:Here 是关于如何在 PHP 中创建具有键值匹配的多维数组的问题。
【问题讨论】:
-
实际问题是什么? “但无法按照我想要的方式解析它”——你想要的结果是什么,你得到的结果是什么?
-
@Felixyz 我想要的结果是通过名称访问对象。例如能够从类别中读取按钮数据
-
不看result2的结构,很难帮你。你说的这些类别是什么?
-
Here 是。我已经分享了问题开头的链接
标签: php objective-c arrays json parsing