JSON匹配NSString与NSDictionary

我试图匹配我从另一个UITableView得到的JSON NSString,在prepareToseg期间与两个JSON包含相同的密钥的nid匹配。 我想要的是,使这个UITableView只显示匹配的NID内容。 我将从第二个UITableView发布2套我的JSON和我的代码。 请帮我出去。

这是myJSON的第一套

[ { node_title: "Fumi", nid: "9", Body: "<p>Fumi Restaurant</p> ", Shop Branch Reference: "8", Shop Enterprise Reference: "<a href="/drupal/node/7">Fumi</a>", Shop Service Time: [ "<div class="time-default"> Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday 10:00am - 8:00pm</div> " ], Shop User Reference: "<a href="/drupal/user/12">suppae</a>" }, { node_title: "Shop Number One", nid: "3", Body: "<p>This is body for shop number one This is body for shop number one This is body for shop number one This is body for shop number one This is body for shop number one This is body for shop number one This is body for shop number one This is body for shop number one This is body for shop number one This is body for shop number one This is body for shop number one</p> ", Shop Branch Reference: "2", Shop Enterprise Reference: "<a href="/drupal/node/1">Fuji</a>", Shop Service Time: [ "<div class="time-default"> Monday, Tuesday, Wednesday, Thursday, Friday 10:00am - 10:00pm</div> ", "<div class="time-default"> Saturday, Sunday 9:00am - 10:00pm</div> " ], Shop User Reference: "<a href="/drupal/user/9">testshop</a>" } ] 

这是我的JSON的第二套

  [ { node_title: "CTW", nid: "8" }, { node_title: "Siam Paragon", nid: "2" } ] 

现在,我设法实现了比赛来解决问题。 我现在的问题是,我需要在匹配后为我的json设置新的值,以便它可以在UITableview上填充。

这是我的代码

 for(int i = 0; i < [_Json count]; i++) { NSString * match =[[_Json valueForKey:@"nid"]objectAtIndex:i]; NSString * branch =[self.detail valueForKey:@"Shop Branch Reference"]; if([match isEqualToString:branch]) { NSLog(@"Found "); 

非常感谢您的帮助。

首先,为了节省你很多的麻烦:如果你把一个块的开头放到行尾,Xcode会很好的格式化它,而不是把你的代码放到屏幕的最右边。

其次,你可以写一个方法来完成所有的处理,并从块中调用它,使你的代码更具可读性。

第三,如果我有一个字典的数组,并希望find一个键/值对“NID”:“8”的字典,我会写

 for (NSDictionary* dict in array) if ([dict [@"nid"] isEqualToString:@"8"]) NSLog (@"Found the dictionary!!!");