0

我有这个 JSON 数据:

{
    "result": {
        "OrderNo": "23456tr4",
        "ProductOrder": "1",
        "TotalCost": "$300",
        "Fname": "wwww",
        "Lname": "wwww",
        "Address": "wwww"
    }
}

我尝试用以下代码解析它:

NSMutableArray *data_holder_array = [NSMutableArray array];

if([response isKindOfClass:[NSDictionary class]]) {

    NSMutableArray *tempDataArray = response;

     NSLog(@"tempDataArraytempDataArraytempDataArray %@",tempDataArray);

    [tempDataArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

        NSMutableDictionary *tempDictionary = [tempDataArray objectAtIndex:idx];

        ISPandingOrderServiceHelper *temp_Data_Model = [[ISPandingOrderServiceHelper alloc] init];
        [temp_Data_Model setAddress:[tempDictionary objectForKey:@"Address"]];
        [temp_Data_Model setFname:[tempDictionary objectForKey:@"Fname"]];
        [temp_Data_Model setLname:[tempDictionary objectForKey:@"Lname"]];
        [temp_Data_Model setOrderNo:[tempDictionary objectForKey:@"OrderNo"]];
        [temp_Data_Model setProductOrder:[tempDictionary objectForKey:@"ProductOrder"]];
        [temp_Data_Model setTotalCost:[tempDictionary objectForKey:@"TotalCost"]];

        [[ISSingletonClass sharedMySingleton] setPandingOrderService:temp_Data_Model];
        [data_holder_array addObject:temp_Data_Model];
    }];

但是当我尝试运行代码时,我在控制台中看到以下错误消息:

Error :-[__NSDictionaryM enumerateObjectsUsingBlock:]: unrecognized selector sent to instance 0x90108d0
2013-10-01 12:39:56.563 InkShop[1688:16c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM enumerateObjectsUsingBlock:]: unrecognized selector sent to instance libc++abi.dylib: terminate called throwing an exception`
4

1 回答 1

0

第 3 行 NSMutableArray *tempDataArray = response; 将响应分配给 MutableDictionary。如果您使用 objectForKey:@"result",您将再次获得另一个 NSmutableDictionary

于 2013-10-01T11:37:32.653 回答