2014-02-17 2 views
0

JSON을 구문 분석하려고 할 때 오류가 발생하며 문제를 이해하지 못합니다. 내 값을 가져오고 싶습니다. "objectForKey"가있는 XML.- [__ NSCFString objectForKey :] : 인스턴스로 전송 된 인식 할 수없는 선택기 문제

내 JSON 파서 :

@implementation contents 

NSDictionary* loadedContent = nil; 

+ (NSDictionary*)getContent:(NSString *)nameInnov 
{ 
    if (loadedContent == nil) { 
     NSError* error = nil; 
     NSString* path = [[NSBundle mainBundle] pathForResource:@"res/contents.json" ofType:nil inDirectory:nil]; 
     loadedContent = [NSJSONSerialization JSONObjectWithData:[[NSFileManager defaultManager] contentsAtPath:path] options:kNilOptions error:&error]; 
     if (error) { 
      NSLog(@"Error while parsing: %@", [error localizedDescription]); 
     } 
    } 
    for (NSString* place in [loadedContent allKeys]) { 
     NSDictionary* contents = [loadedContent objectForKey:place]; 
     for (NSString* key in [contents allKeys]) { 
      NSDictionary* info = [contents objectForKey:key]; 
      if ([[info objectForKey:@"innov"] isEqualToString:nameInnov] == YES) { 
       return info; 
      } 
     } 
    } 
    return nil; 
} 

- (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qName attributes:(NSDictionary*)attributeDict 
{ 

} 

내보기 중 하나에서이 파서 전화 해요 :

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [LoginModel setOFFLandingPage]; 

    NSDictionary* contentView = [contents getContent:@"wonderbra"]; 

    //self.nameInnovTextField.text = [info objectForKey:@"titre"]; 
} 

을 그리고 난이 오류가 얻을 : 돕는

2014-02-17 15:56:45.206 App[651:60b] -[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x1559a450 
2014-02-17 15:56:45.208 App[651:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x1559a450' 
*** First throw call stack: 
(0x2edc3f4b 0x396656af 0x2edc78e7 0x2edc61cb 0x2ed154d8 0xbf945 0xb6fab 0x3153b37b 0x315e60f1 0x315e6007 0x315e55e3 0x315e530d 0x315e507d 0x315e5015 0x31536da3 0x311bdc6b 0x311b947b 0x311b930d 0x311b8d1f 0x311b8b2f 0x311b285d 0x2ed8f1cd 0x2ed8cb71 0x2ed8ceb3 0x2ecf7c27 0x2ecf7a0b 0x339f8283 0x3159b049 0xbe5e5 0x39b6dab7) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

들으을 !

답변

0

오류 메시지

-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x1559a450 

당신이 실제로 NSDictionary에 그 메시지를 보내려는 -presumably NSString 인 객체에 objectForKey: 메시지를 보내려고하고 있음을 나타냅니다. JSON 입력이 생각대로 구성되어 있습니까?

+0

사실 내 JSON 구조였습니다. 내 파서의 "For Loop"를 다음과 같이 변경합니다. ([loadedContent allKeys]의 NSString * 장소) { NSDictionary * info = [loadedContent objectForKey : place]; if ([[infoObjectForKey : @ "혁신"] isEqualToString : nameInnov] == 예) { 반환 정보; } } Thx !! – testoverblaireau

관련 문제