将数据从NSDictionary传递到NSMutableDictionary的问题

时间:2011-12-13 07:26:32

标签: iphone

我正在尝试使用json框架访问web服务。

代码:

NSDictionary *allData;
NSMutableDictionary *displayData;
NSString *string = [[NSString alloc] initWithFormat:@"http://localhost/Gangbucks.svc/GetDealList"]; 
NSURL *jsonURL = [NSURL URLWithString:string];  
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL];  
self.allData = [jsonData JSONValue];  
NSLog(@"allData  value is1:%@", self.allData);      
self.displayData = [[NSMutableDictionary alloc] initWithDictionary:self.allData];
NSLog(@"displayData  value is2:%@", self.displayData);  

allData工作正常但我在displayData

上收到错误
2011-12-13 14:59:23.875 IPhone[352:207] -[__NSArrayM getObjects:andKeys:]: unrecognized selector sent to instance 0x59e1c20
2011-12-13 14:59:23.878 IPhone[352:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM getObjects:andKeys:]: unrecognized selector sent to instance 0x59e1c20'
*** Call stack at first throw:

是否可以将数据从NSDictionary传递到NSMutableDictionary?

1 个答案:

答案 0 :(得分:3)

allData显然是NSArray,而不是NSDictionary。你应该回去查看你的JSON。顶层可能有一个数组。