gpt4 book ai didi

objective-c - NSDictionary 过滤和排序

转载 作者:行者123 更新时间:2023-12-03 21:10:38 27 4
gpt4 key购买 nike

我正在开发一个使用 JSON API 的应用程序,并且我正在使用 Objective C 框架的 JSON 将数据放入 NSDictionary 中。字典看起来像这样:

({
admitted = "<null>";
agreed = "<null>";
"area_id" = 1;
"area_name" = "Digitales, Urheber-/Patentrecht, Datenschutz";
created = "2010-08-17 12:41:03";
"current_draft_content" = Bla Bla Bla";
"current_draft_created" = "2010-08-17 12:42:44";
"current_draft_formatting_engine" = compat;
"discussion_url" = "http://piratenpad.de/OpenSourceZwang";
id = 502;
"informed_supporter_count" = 11;
"issue_accepted" = "";
"issue_admission_time" = "8 days";
"issue_closed" = "";
"issue_created" = "2010-08-17 12:41:03";
"issue_discussion_time" = "15 days";
"issue_fully_frozen" = "";
"issue_half_frozen" = "";
"issue_id" = 242;
"issue_population" = 372;
"issue_ranks_available" = 0;
"issue_state" = new;
"issue_verification_time" = "8 days";
"issue_vote_later" = 0;
"issue_vote_now" = 0;
"issue_voter_count" = "<null>";
"issue_voting_time" = "8 days";
name = "Alte & unsupportete Software, muss Open Source werden";
"negative_votes" = "<null>";
"policy_initiative_quorum_den" = 100;
"policy_initiative_quorum_num" = 10;
"policy_issue_quorum_den" = 100;
"policy_issue_quorum_num" = 10;
"policy_majority_den" = 2;
"policy_majority_num" = 1;
"policy_majority_strict" = 1;
"positive_votes" = "<null>";
rank = "<null>";
revoked = "<null>";
"satisfied_informed_supporter_count" = 7;
"satisfied_supporter_count" = 7;
"suggested_initiative_id" = "<null>";
"supporter_count" = 11;
},
{
admitted = "<null>";
agreed = "<null>";
"area_id" = 1;
"area_name" = "Digitales, Urheber-/Patentrecht, Datenschutz";
created = "2010-08-17 14:09:14";
"current_draft_content" = "Bla Bla Bla";
"current_draft_created" = "2010-08-17 14:09:31";
"current_draft_formatting_engine" = compat;
"discussion_url" = "";
id = 508;
"informed_supporter_count" = 0;
"issue_accepted" = "2010-08-14 01:51:45";
"issue_admission_time" = "15 days";
"issue_closed" = "";
"issue_created" = "2010-08-14 01:34:26";
"issue_discussion_time" = "30 days";
"issue_fully_frozen" = "";
"issue_half_frozen" = "";
"issue_id" = 30;
"issue_population" = 603;
"issue_ranks_available" = 0;
"issue_state" = accepted;
"issue_verification_time" = "15 days";
"issue_vote_later" = 9;
"issue_vote_now" = 0;
"issue_voter_count" = "<null>";
"issue_voting_time" = "15 days";
name = "Grundrecht: Alternative Formulierung";
"negative_votes" = "<null>";
"policy_initiative_quorum_den" = 100;
"policy_initiative_quorum_num" = 10;
"policy_issue_quorum_den" = 100;
"policy_issue_quorum_num" = 10;
"policy_majority_den" = 3;
"policy_majority_num" = 2;
"policy_majority_strict" = 0;
"positive_votes" = "<null>";
rank = "<null>";
revoked = {
};
"satisfied_informed_supporter_count" = 0;
"satisfied_supporter_count" = 0;
"suggested_initiative_id" = "<null>";
"supporter_count" = 0;
}
)

获取“issue_id”为 2 或 6 的所有对象或显示分组的 UITabeView 以及一组中具有相同“issue_id”的所有对象的好方法是什么?

最佳答案

您可以使用 NSSortDescriptor 进行排序:

    NSSortDescriptor *dateSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"issue_id" ascending:YES selector:@selector(compare:)] autorelease];
[youDictionaryArray sortUsingDescriptors:[NSArray arrayWithObjects:dateSortDescriptor, nil]];

和/或 NSPredicate 仅获取某些 ID:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(issue_id == %i)", 2];
NSArray *newArray = [youDictionaryArray filteredArrayUsingPredicate:predicate];

关于objective-c - NSDictionary 过滤和排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3503141/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com