2012-07-15 3 views
0

나는이 JSON 배열 구문 분석하려고 해요 :목표 - C JSON 구문 분석 오류

http://www.ifanatic.hu/api/get_recent_posts/?dev=1

을하지만이 오류를 얻을 :

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 

NSArray* latestPosts = [responseString JSONValue]; 

NSDictionary* post = [latestPosts objectAtIndex:[latestPosts indexOfObject:0]]; 

NSString* title = [post objectForKey:@"title"]; 

label.text = [NSString stringWithFormat:@"Title: %@", title]; 
다음은

2012-07-15 22:31:59.038 JSONTest[610:f803] -[__NSCFDictionary indexOfObject:]: unrecognized selector sent to instance 0x6a92850 
2012-07-15 22:31:59.040 JSONTest[610:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary indexOfObject:]: unrecognized selector sent to instance 0x6a92850' 
*** First throw call stack: 
(0x13d7052 0x1568d0a 0x13d8ced 0x133df00 0x133dce2 0x236b 0xa23a59 0xa21e94 0xa22eb7 0xa21e4f 0xa21fd5 0x966f6a 0x3989bbd 0x3a565ea 0x3980298 0x3a5616b 0x3980137 0x13ab97f 0x130eb73 0x130e454 0x130ddb4 0x130dccb 0x12c0879 0x12c093e 0x2ea9b 0x1cb8 0x1c15) 
terminate called throwing an exception 

내 소스

+0

기 vagy 테 AZ iFanatictól? Repabali? –

답변

3

JSON을 구문 분석 할 때 JSON 오브젝트의 루트 요소가 NSDictionary로 변환됩니다. 그리고 NSDictionary는

indexOfObject: 

메시지에 응답하지 않습니다. 당신이 필요가있는 무엇을 사용하는 것입니다

NSDictionary *post = [[latestPosts objectForKey:@"posts"] objectAtIndex:0];