我有这样的 NSMutablearray
(它是一个 JSON 数组)
{
"notification_list":[
{
"TYPE":"ARTIST",
"ID":"07",
"DTEXT":"Now you can listen to the songs of ARTIST1",
"ADDEDDATE":"27th June, 2013 4:44 pm."
},
{
"TYPE":"BRAND",
"ID":"http:\/\/www.me.lk\/",
"DTEXT":"M Entertainment have been joined with Mobile Music",
"ADDEDDATE":"27th June, 2013 3:37 pm."
},
{
"TYPE":"ARTIST",
"ID":"03",
"DTEXT":"Now you can listen to the songs of ARTIST2",
"ADDEDDATE":"27th June, 2013 3:37 pm."
},
{
"TYPE":"ALBUM",
"ID":"Nava Ridgma",
"DTEXT":"Get new album of ARTIST3, Nava ridma",
"ADDEDDATE":"27th June, 2013 3:37 pm."
},
{
"TYPE":"SONG",
"ID":"05",
"DTEXT":"New Song added to the Mobile Music - Hanthane Kandumuduna by ARTIST5, Album - Aradhana",
"ADDEDDATE":"27th June, 2013 3:37 pm."
}
]
}
现在我想在这个 NSMutablearray
{
"TYPE":"ALBUM",
"ID":"Nava Ridgma",
"DTEXT":"Get new album of ARTIST3, Nava ridma",
"ADDEDDATE":"27th June, 2013 3:37 pm."
}
我如何从这个 NSMutablearray
搜索这个对象并获取索引。
谁能帮帮我。
谢谢
最佳答案
尝试
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"TYPE == [cd] %@",@"ALBUM"];
NSInteger index = [array indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
return [predicate evaluateWithObject:obj];
}];
NSLog(@"Index of object %d",index);
关于ios - 如何获取 NSMutablearray 中特定对象的索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17543621/