2012-05-29 40 views
1

我是很新的iOS開發,我想一些添加值從NSMutableDictionaryNSMutableArray,當我運行代碼,我得到這個錯誤錯誤的NSMutableArray

2012-05-29 14:09: 34.913 iShop [7464:F803] - [__ NSCFArray objectForKey:]: 無法識別的選擇發送到實例0x6e423d0 2012-05-29 14:09:34.915 iShop [7464:F803] *終止應用程序由於未捕獲 異常 'NSInvalidArgumentException' ,原因:' - [__ NSCFArray objectForKey:]:無法識別的選擇器發送到實例0x6e423d0' *第一擲調用堆棧:(0x13cb022 0x155ccd6 0x13cccbd 0x1331ed0 0x1331cb2 0x2bb7 0x13cce42 0x93b9df 0x139f94f 0x1302b43 0x1302424 0x1301d84 0x1301c9b 0x12b47d8 0x12b488a 0x15626 0x28bd 0x2825) 終止叫做拋出異常(LLDB)

下面

是我的代碼:

-(void) getData:(NSData *) response { 
    NSError *error; 

    NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&error]; 
    //NSLog(@"%@", json); 

    jsonArray = [[NSMutableArray alloc] init]; 

    jsonArray = [json objectForKey:@"Name"]; 

    NSLog(@"%@", jsonArray); 

} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    jsonURL = [NSURL URLWithString:@"http://localhost:8888/read_product_list.php"]; 
    dispatch_async(BgQueue, ^{ 
     NSData* data = [NSData dataWithContentsOfURL:jsonURL]; 
     [self performSelectorOnMainThread:@selector(getData:) 
           withObject:data waitUntilDone:YES]; 
    }); 
} 

回答

2

JSONObjectWithData返回類型爲id的對象。取決於您收到的json數據的結構。 接收到的數據是NSDictionaryNSArray。在你的情況下,我猜測頂級對象的類型爲NSArray,它不響應objectForKey

相關問題