1

我在尝试将对象从 an 加载NSDictionary到 an 时遇到问题NSMutableDictionary- 代码如下:

dictListData = [[NSMutableDictionary alloc] initWithCapacity:200];

...

NSError *jsonError = nil;
NSDictionary *jsonResultDict = [NSJSONSerialization JSONObjectWithData:[httpRequestCopy responseData] options:kNilOptions error:&jsonError];
NSDictionary *tempDataset = [[jsonResultDict objectForKey:@"result"] objectAtIndex:0]; 

NSLog(@"tempDataset = %@", tempDataset);

[dictListData addEntriesFromDictionary:tempDataset];   // <-- Error here

NSLog命令以字典样式格式输出数据,因此我知道数据在那里,但是 addEntriesFromDictionary 命令失败并出现错误:

'NSInvalidArgumentException' [NSMutableDictionary addEntriesFromDictionary:]: dictionary argument is not an NSDictionary'.

我尝试过对 tempDataset 进行类型转换,但没有任何区别。有任何想法吗?

我正在使用 Xcode 4.3.2,针对 iOS SDK 5.1,启用了 ARC。

jsonResultDict = {
    result =     (
                (
                        {
                stCode = 000477065;
                stDesc1 = "TIMER KNOB";
                stQtyFree = 0;
                stQtyInStock = 0;
            },
                        {
                stCode = 0010311;
                stDesc1 = "DBLE TAPER CHUCK CAP";
                stQtyFree = 10;
                stQtyInStock = 10;
            },
                        {
                stCode = "0016-103";
                stDesc1 = "1/8 I.D";
                stQtyFree = 0;
                stQtyInStock = 0;
            },
                        {
                stCode = "0016-104";
                stDesc1 = "1/4 I.D";
                stQtyFree = 0;
                stQtyInStock = 0;
            },
                        {
                stCode = "0016-157";
                stDesc1 = "1/8 x 1/16 X 1/8 TEE";
                stQtyFree = 0;
                stQtyInStock = 0;
            }
        )
    );
}
4

2 回答 2

2

这似乎tempDataset是一个NSArray类。

于 2012-04-13T13:23:00.930 回答
0

Flink 回答它是一个 NSArray 类应该是正确的。此外,如果您确实需要将 an 转换NSDictionaryNSMutableDictionary,它的使用要容易得多myDictionary.mutableCopy

于 2012-04-13T13:31:16.633 回答