ios - 如何在ios objective-c 中过滤Json数据
<p><p>JSON 解析有问题。 <br/>
我得到 JSON 数据,我想显示与 <strong>restid</strong> 匹配的项目。<br/>
我有一个 tableView 来显示不同的餐厅信息,每个餐厅也有自己的评论单元来评论这家餐厅。<br/>
所以,我会过滤 JSON 数据。<br/>
让每个餐厅评论单元都能获得自己的评论。<br/></p>
<p>这是我的 JSON:</p>
<pre><code>(
{
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;
}
)
</code></pre>
<p>这是我的代码:<br/>
<br/>
它可以显示我的 tableView 中的所有数据以及不同餐厅评论单元中的所有相同数据。</p>
<pre><code>- (void)getCommentInfo:(id)sender {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *url = ;
NSData *data = ;
NSArray *comment = ;
NSLog(@"Comment is %@",comment);
self.commentArray = ;
dispatch_async(dispatch_get_main_queue(), ^{
;
});
});
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>试试这个,我没有测试代码,如果你有问题,请告诉我。</p>
<pre><code>NSArray *filteredArray = [comment filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id elem, NSDictionary *bindings) {
return ( == <your_rest_id>)
}]];
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何在ios objective-c 中过滤Json数据,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39201471/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39201471/
</a>
</p>
页:
[1]