我有一個實體類的數組(例如SubmittedAnswer)。其JSON格式如下所示。Iterar遍歷實體數組,並根據「其他關鍵字」matche的值獲取某個鍵的值
{
"submittedAnswers": [{
"submittedQuestionId": "C7B3C4BE-CC3C-438F-A118-E798884A5FE0",
"serialNumber": 4,
"option": " it has a very large mass.",
"testQuestionId": "55230160-b905-47d5-a91c-e1dda6dd0634",
}, {
"submittedQuestionId": "9A6E9EA8-1BC0-4ED9-81E8-28B7E554D5E0",
"serialNumber": 1,
"option": " downward",
"testQuestionId": "fd0b3ae0-e999-48a6-89b8-a89b02e7b793",
}]
}
我想找到 「選項」 從數組,其 「submittedQuestionId」 場 「的東西......」。我不想用循環。 目前我正在使用以下代碼。
NSString *submittedQuestionId = "something...."
int index = [[submittedAnswers valueForKey:@"submittedQuestionId"] indexOfObject:submittedQuestionId];
NSString *option = [[submittedAnswers valueForKey:@"option"] objectAtIndex:index];
我需要更好的解決方案來解決這個問題。