繁体   English   中英

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

[英]Error in parse json response and store model class

我有以下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`

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM