2012-03-22 4 views
0

을 :으로 반복 및지도 JSON 사전 객체의 배열 구축 - 내가 JSON 웹 서비스에서이 응답에게있어 목표 C

categoria =  (
       { 
      "id_categoria" = 61; 
      imagen = "http://exular.es/mcommerce/image/data/ipod_classic_4.jpg"; 
      nombre = Gorras; 
     }, 
       { 
      "id_categoria" = 59; 
      imagen = "http://exular.es/mcommerce/image/data/ipod_touch_5.jpg"; 
      nombre = Camisetas; 
     }, 
       { 
      "id_categoria" = 60; 
      imagen = "http://exular.es/mcommerce/image/data/ipod_nano_1.jpg"; 
      nombre = Pantalones; 
     } 
    ); 
} 

그것은 코드의이 작품에서 사전에 공급된다

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];  
    //data =nil; 
    NSLog(@"JSNON %@", responseString); 

    NSDictionary *results = [responseString JSONValue]; 


    NSLog(@"JSNON %@", results); 

나는 사전에있는 모든 범주를 반복하고 "속성"이름 "과 이미지 카테고리 개체를 포함하는있는 NSArray를 작성해야합니다.

많은 감사

답변

1
NSArray *categories = [results objectForKey:@"categoria"]; 

이렇게하면 범주 개체의 배열이 만들어집니다. 이 사전/객체 배열을 사용자 정의 객체에 전달하거나 필요한 객체를 반복하여 반복 할 수 있습니다.

이것은 init이 사전을 처리하도록 설정되었다고 가정합니다. 알아야 할 코드가 충분하지 않지만 여기에서 알아낼 수 있어야합니다.

+0

감사합니다. Bill, 매우 도움이되었습니다. – roof