JSON parsing on iPhone SDK

后端 未结 5 1256
灰色年华
灰色年华 2021-01-17 01:29

I have a certain json:

[
    {
        \"id\"        : 42422422,
        \"created\"   : 1329684013,
        \"name\"          : \"Test\"
    },
    {
               


        
5条回答
  •  礼貌的吻别
    2021-01-17 01:52

    You should check if your result is an array or a dictionary first.

    if ([jsonArray isKindOfClass:[NSArray class]]) {
         //process results
    } else if ([jsonArray isKindOfClass:[NSDictionary class]]) {
        NSDictionary *errorInfo = [(NSDictionary *)jsonArray objectForKey:@"error"];
        //handle error...
    }
    

提交回复
热议问题