iphone - 使用块从数组中获取子数组非常令人困惑
我有一个对象数组(json 对象) 每个对象都具有以下性质:
{
author = "<null>";
category = {
"created_at" = "2011-02-06T18:11:39Z";
id = 4;
name = lawyers;
};
"created_at" = "<null>";
id = 693;
"mobile_user_id" = "<null>";
"rating_count" = 0;
status = 1;
text = "A brain walks into a bar and says, \"I'll have a pint of beer please. \"The barman looks at him and says \"Sorry, I can't serve you.\" \"Why not?\" asks the brain. \"You're already out of your head.\"";
title = "A brain goes to a local bar";
}
从这些对象数组中,我想找到类别 id = 4 的对象并创建一个子数组。
有人可以帮助我使用块并从数组中获取子数组吗?
I'm having an array of objects (json objects)
each object is of following nature:
{
author = "<null>";
category = {
"created_at" = "2011-02-06T18:11:39Z";
id = 4;
name = lawyers;
};
"created_at" = "<null>";
id = 693;
"mobile_user_id" = "<null>";
"rating_count" = 0;
status = 1;
text = "A brain walks into a bar and says, \"I'll have a pint of beer please. \"The barman looks at him and says \"Sorry, I can't serve you.\" \"Why not?\" asks the brain. \"You're already out of your head.\"";
title = "A brain goes to a local bar";
}
From those array of objects, I want to find objects whose category has id = 4 and make a sub array.
Can some one help me in using blocks and get sub array from array please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通过“使用块”,你的意思是使用 NSArray 的方法,例如
然后它看起来像
这就是你所要求的,但我宁愿使用
filteredArrayUsingPredicate:
像这样:I guess by "using blocks", you mean using a method of NSArray like
Then it would look like
That's for what you asked, but I'd rather use
filteredArrayUsingPredicate:
like this: