解析json响应和存储模型类时出错

时间:2013-10-01 07:04:01

标签: iphone ios objective-c json parsing

我有这个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`

1 个答案:

答案 0 :(得分:0)

第3行 NSMutableArray * tempDataArray = response; 将响应分配给MutableDictionary.Again如果你使用objectForKey,你将获得另一个NSmutableDictionary:@“result”