簡體   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