Iphone 在应用程序中解析JSON提要时出现问题

Iphone 在应用程序中解析JSON提要时出现问题,iphone,objective-c,ios,json,Iphone,Objective C,Ios,Json,以下JSON提要包含订单 当每个订单不包含密钥(不能使用objectForKey)时,如何检索?在开口括号和第一个卷曲括号之间没有键 [ <----- { <----- "person": { "address": "My road", "city": "My City", "name": "My Name", }, "orderDate": "30.05.

以下JSON提要包含订单

当每个订单不包含密钥(不能使用objectForKey)时,如何检索?在开口括号和第一个卷曲括号之间没有键

[ <-----
    { <-----
        "person": {
            "address": "My road",
            "city": "My City",
            "name": "My Name",
        },
        "orderDate": "30.05.2012 10:27",
        "orderId": 10001,
        "orderlines": [
            {
                "unit": {
                    "unitId": "RA005",
                    "name": "My Unit name",
                },
                "id": 10007,
                "deliveryInfo": {
                    "count": 1,
                    "date": "30.05.2012",
                    "format": "MY_FORMAT",
                },
                "sum": 0,
                "details": "Testing",
                "priority": 3,
            }
        ],
        "received": true,
        "status": "REGISTERED",
        "sumPrice": 0
    },
    {
        "person": {
            "address": "My road 2",
            "city": "My City 2",
            "name": "My Name 2",
        },
        "orderDate": "30.04.2012 10:27",
        "orderId": 10002,
        "orderlines": [
            {
                "unit": {
                    "unitId": "RA006",
                    "name": "My Unit name 2",
                },
                "id": 10008,
                "deliveryInfo": {
                    "count": 2,
                    "date": "01.06.2012",
                    "format": "MY_FORMAT",
                },
                "sum": 0,
                "details": "Testing",
                "priority": 2,
            }
        ],
        "received": true,
        "status": "REGISTERED",
        "sumPrice": 0
    }
]
[每当您看到[](方括号)时,它都表示数组。因此使用object at index返回at index。一种方法是将对象传递到数组中,如

NSMutableArray *arr = (NSMutableArray*) jsonData;

由于json的根是一个数组

NSError *e = nil;
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &e];

if (!jsonArray) {
  NSLog(@"Error parsing JSON: %@", e);
} else {
   for(NSDictionary *item in jsonArray) {
      NSLog(@"Item: %@", item);
   }
}

这是一个项目数组。您可以使用
objectAtIndex:
检索它们。