我有一本从解析 JSON 中提取的其他字典中包含子项的字典。结构如下所示:
{
children = (
{
children = (
{
hasArticles = 1;
hasWideIcon = 0;
label = biological;
urlId = 9950000123891;
},
{
hasArticles = 1;
hasWideIcon = 0;
label = White;
urlId = 9950000123892;
},
{
hasArticles = 1;
hasWideIcon = 0;
label = "various flavors";
urlId = 9950000123893;
},
{
hasArticles = 1;
hasWideIcon = 0;
label = "different tastes creamy";
urlId = 9950000123894;
},
{
hasArticles = 1;
hasWideIcon = 0;
label = "yogurt drinks";
urlId = 9950000123895;
},
{
hasArticles = 1;
hasWideIcon = 0;
label = "Yogurt mix";
urlId = 9950000123896;
},
{
);
hasArticles = 0;
hasWideIcon = 0;
label = "types of yogurt"; //those above are the children of the "types of yogurt"
urlId = 9950000123890;
},
{
children = (
{
hasArticles = 1;
hasWideIcon = 0;
label = White;
urlId = 9950000123906;
},
{
hasArticles = 1;
hasWideIcon = 0;
label = "various flavors";
urlId = 9950000123907;
},
{
hasArticles = 1;
hasWideIcon = 0;
label = Pappareale;
urlId = 9950000123909;
}
);
hasArticles = 0;
hasWideIcon = 0;
label = "yogurt healthy"; //those above are the children of the yogurt healthy
urlId = 9950000123905;
},
{
hasArticles = 1;
hasWideIcon = 0;
label = "puddings and creams";
urlId = 9950000123911;
},
{
hasArticles = 1;
hasWideIcon = 0;
label = "Snack dessert";
urlId = 9950000123913;
},
{
hasArticles = 1;
hasWideIcon = 0;
label = "various Dessert";
urlId = 9950000123914;
}
);
hasArticles = 0;
hasWideIcon = 0;
label = "Yogurt and Dessert ";
urlId = 9950000123889;
},
我的代码
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"%d", [webData length]);
NSString *strResult =[[NSString alloc]initWithData:webData encoding:NSUTF8StringEncoding];
NSDictionary *result =[strResult JSONValue];
for (id obj in result){
NSLog(@"%@", result);
/*A part of the result is written above, but in reality is much
longer and includes all possible products in a supermarket*/
}
}
如何提取“yogurtDessert”的孩子
- 酸奶的种类(有小孩的)
- yogurt-healthy(谁有孩子)
- 布丁和面霜(不含儿童)
- 点心甜点(不含儿童)
- 各种甜点(不含儿童)
那我怎么提取给不知道提前知道的yogurtDessert的孩子们呢?
我需要创建一个包含超市产品类别的字典数组(在这个例子中只有酸奶和甜点,总共 23 个元素),然后我必须创建另一个字典数组,每个字典都包含每个产品的子类别,那是成千上万。我考虑过使用 NSPredicate ,但它是字典。我必须过滤其他字典中的字典