2012-03-30 2 views
0
을 나는이 JSON 메시지 "노드"노드에 액세스하려고 해요

:이 코드는 JSON 메시지에 내부 노드에 액세스 할 수 없습니다 - IOS

{ 
    "nodes": [ 
     { 
     "node": { 
      "title": "Jornada del Fútbol Profesional contra el hambre", 
      "description": " 
      "image": "", 
      "fecha": "", 
      "nid": "", 
      "noticia_relacionada_1_path": "", 
      "noticia_relacionada_2_path": "", 
      "image_small_2": "" 
     } 
     } 
    ] 
} 

:

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

NSDictionary *results = [responseString JSONValue]; 

NSDictionary *nodes = [results objectForKey:@"nodes"]; 

결과 사전 1 개의 중요한 결과가 있습니다. 노드 사전에는 10 개의 키 결과가 있습니다. , 사전을

NSString *node = [nodes valueForKey:@"node"]; 

NSArray *nodeArray = [nodes objectForKey:@"node"]; 

NSDictionary *nodeDic = [nodes objectForKey:@"node"]; 

많은 감사

답변

3

당신이

NSDictionary *nodes = [results objectForKey:@"nodes"]; 

으로 검색 개체되지 않은 :이 모든 옵션을 가진 노드에 액세스하려고 할 때, 나는 아무 결과를 얻지 는 사전 "키"가있는 항목이 하나있는 배열입니다. 첫 번째 노드를 얻으려면 :

NSArray *nodes = [results objectForKey:@"nodes"]; 

NSDictionary firstNodeDict = [[nodes objectAtIndex: 0] objectForKey: @"node"]; 
+0

감사합니다. jeremy, 도움이되었습니다. – roof

관련 문제