开发者

Parsing an NSDictionary in one operation ( remove loop).

开发者 https://www.devze.com 2023-03-24 06:45 出处:网络
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:

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

精彩评论

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