我現在正在學習Xcode,我有一個項目是使用php從Mysql數據庫中提取數據並通過json傳遞給我的應用程序。在數據庫中,所有變量都設置爲utf8_bin。Xcode json錯誤
這裏是PHP:
header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/json');
echo json_encode($this->Idea_model->get($id));
這裏是輸出的JSON的snipet:
[{"id":"1","title":"JWT blood sucka","objective":"test ","mission":"test","design_time":"80","development_time":"80","votes":"0","user_id":"0","date_created":"2012-08-03","date_modified":"2012-08-03","active":"1"},{"id":"2","title":"ford - liveDealer","objective":"to increce ","mission":"thid id a es","design_time":"80","development_time":"80","votes":"1","user_id":"1","date_created":"0000-00-00","date_modified":"0000-00-00","active":"1"}]
在Xcode我使用這個功能在JSON [參考教程拉: http://www.raywenderlich.com/5492/working-with-json-in-ios-5]
(void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSArray* latestLoans = [json objectForKey:@"loans"]; //2
NSLog(@"loans: %@", latestLoans); //3
}
when我使用這個JSON文件從它的工作原理 http://api.kivaws.org/v1/loans/search.json?status=fundraising
但是當我使用我的JSON文件我得到以下錯誤。
[8690:207] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x6a10400
Current language: auto; currently objective-c
顯然是有一個問題,我的JSON輸出爲我打印從教程文件中的內容在我的PHP文件和工作過。
我也嘗試過在iOS模擬器中「重置內容和設置」。
有什麼想法?
感謝您的回答,我正在做更多的研究並將結果發佈,但您的幫助已經指出了我的正確方向。 – chris 2012-08-09 07:02:43