2012-04-11 6 views
0

json 파일을 탐색 할 때 약간의 도움이 필요합니다. 내가 찾고 있어요중첩 된 json 데이터를 탐색하는 방법

이 같은 수익에서 모든 국가 이름을 얻을 : 내가 아는 또는 (225), (206)의 목록이 없을 때

[{"country": 
    { 
    "225":["United Kingdom","Europe"], 
    "206":["Switzerland","Europe"], 
    "176":["Romania","Europe"], 
    "127":["Madagascar","AMEA"], 
    "217":["Tunisia","AMEA"] 
    } 
    }] 

어떻게이 얻을 것이다 .. .기타? 당신이 키 (예 : 225)가있는 경우

+0

안녕하세요, 나는 C#에서 유사한 json 응답을 생성해야합니다. 이걸 좀 도와 주실 래요? 나는 나의 질문을 여기에 올렸다 .http : //stackoverflow.com/questions/10106716/linq-to-json-response/10106774comments12949266_10106774 –

답변

3
var arr = [ 
    { 
     "country": { 
      "225":["United Kingdom","Europe"], 
      "206":["Switzerland","Europe"], 
      "176":["Romania","Europe"], 
      "127":["Madagascar","AMEA"], 
      "217":["Tunisia","AMEA"] 
     } 
    } 
] 

arr[0]["country"]["225"]은 사용 ["United Kingdom","Europe"]

당신이 키 (및 해당 값)의 목록을 확보하려는 경우와 배열을 반환

var countryObj = arr[0]["country"]; 
for (key in countryObj) { 
    if (countryObj.hasOwnProperty(key)) { 
     console.log(key);    /* e.g. 206 */ 
     console.log(countryObj[key]); /* e.g. ["Switzerland","Europe"] */ 
     console.log(countryObj[key][0]); /* e.g. "Switzerland" */ 
    } 
} 
+0

감사 칼데론 - 나는 다른 예를 볼 때 어떤 의미가 없다. 탐색 배열. 건배 :) – user1326488

0

배열을 사용할 수도 있습니다.

키 255,256을 알지 못해서 국가를 얻고 싶다면 probab 좋은 방법은 좋은 jquery 개체를 우리가 jquery 우리를 건너는 것입니다

$(arr[0]["country"]).each(function(key,country){ 
    alert(country); 
}) 
관련 문제