how to parse array of objects using json for iphone

后端 未结 2 1050
太阳男子
太阳男子 2020-12-30 14:17

I have a problem parsing the array of objects from the JSON result.

[
    {
        \"first_name\":\"vijay\",
        \"last_name\":\"last\",
        \"credi         


        
2条回答
  •  悲&欢浪女
    2020-12-30 14:33

    @Dan Ray answer is correct, but if you want to avoid third-party librairies you can use NSJSONSerialization:

    Assuming that NSData *responseData is containing your JSON.

    NSArray *userData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:nil];
    
    NSMutableArray *creditCards = [NSMutableArray array];
    for (NSDictionary *user in userData) {
        [creditCards addObject:[user objectForKey:@"creditCardNumber"]];
    }
    

    Source: NSJSONSerialization.

提交回复
热议问题