【发布时间】:2016-08-29 08:13:04
【问题描述】:
JSON 解析有问题。
我得到 JSON 数据,我想显示与 restid 匹配的项目。
我有一个 tableView 来显示不同的餐厅信息,每家餐厅也有自己的评论单元来评论这家餐厅。
所以,我会过滤 JSON 数据。
让每个餐厅评论单元都能获得自己的评论。
这是我的 JSON:
(
{
comment = "very good";
food = chicken;
name = Tom;
restid = 1;
score = 4;
},
{
comment = nice;
food = coffee;
name = Jack;
restid = 3;
score = 3;
},
{
comment = tasty;
food = pizza;
name = Mary;
restid = 17;
score = 5;
},
{
comment = unlike;
food = none;
name = Gigi;
restid = 33;
score = 1;
},
{
comment = delicious;
food = juice;
name = Bruce;
restid = 45;
score = 5;
}
)
这是我的代码:
它可以显示我的 tableView 中的所有数据以及不同餐厅评论单元中的所有相同数据。
- (void)getCommentInfo:(id)sender {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *url = [NSURL URLWithString:@"http://localhost:8888/foodComment_json.php"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSArray *comment = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"Comment is %@",comment);
self.commentArray = [NSMutableArray arrayWithArray:comment];
dispatch_async(dispatch_get_main_queue(), ^{
[self.detailCommentTableView reloadData];
});
});
}
【问题讨论】:
-
使用
NSPredicate -
感谢您的帮助。
标签: ios objective-c iphone json