2013-06-17 2 views
0

간단한 json 응답에서 데이터를 가져 오려고합니다. NSDictionary에서 json 데이터 가져 오기

첫 번째 로그

내가 뭘 잘못 [__NSCFString objectForKey:]: unrecognized selector sent to instance 0x72de3b0

를 얻을 그러나 나는 그것에서 objectForKey 사용할 수 없습니다, 내가 access_token이라는 항목을 찾을 수 있음을 보여줍니다?

for(NSDictionary *item in authResponse) 
    { 
     NSString *s1 = @"access_token"; 
     NSString *s2 = [item description]; 

     NSLog(@"access desc: %@", [item description]); 
     if([s1 isEqualToString:s2]){ 
      NSLog(@"Item: %@", [item objectForKey:@"access_token"]); 
     } 
    } 
+1

'NSString' 객체가 아닌'NSString' 객체에서'objectForKey'를 호출하고 있습니다. – trojanfoe

+0

내 json 객체가 올바른 json 객체입니다. 어떻게 json 문자열을 사전으로 변환합니까? –

답변

1

authResponse 객체 그러나 그것은 다른 NSDictionary 개체를 포함하여 그 안에 많은 다른 유형을 포함, NSDictionary 개체입니다.

for (NSObject *item in authResponse) 
{ 
    if ([item isKindOfClass:[NSDictionary class]]) 
    { 
     NSDictionary *dictItem = (NSDictionary *)item; 
     // do thing with sub-dictionary 
    } 
    else if ([item isKindOfClass:[NSString class]]) 
    { 
     NSString *stringItem = (NSString *)item; 
     // do thing with string item 
    } 
    else if ([item isKindOfClass:[NSNumber class]]) 
    { 
     NSNumber *numberItem = (NSNumber *)item; 
     // do thing with number item 
    } 
} 
+0

큰 충고, 잘 했어, 고마워! –