开发者

Parsing an NSDictionary in one operation ( remove loop).

Could you please guide me on how not to use a for loop in this example? I want to execu开发者_开发百科te it one operation if possible:

NSArray *statuses = [parser objectWithString:json_string error:nil];

for (NSDictionary *status in statuses) {                  
    test = [status objectForKey:@"USER_ID"];
}

Thanks.


 NSArray *statuses = [parser objectWithString:json_string error:nil];


if ([statuses count]>0) {

        test=[[statuses objectAtIndex:0] objectForKey:@"USER_ID"];      

}


If you know that the NSArray has only one element (or that the NSDictionary you want is always the first, or at some other fixed position), use [statuses objectAtIndex:0] (or whatever index) to fetch the status element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜