2013-09-28 3 views
0

객체의 모든 부분지고 :JQuery와 JSON 내가 지금처럼 일부 개체에 설정된 JSON 파일이

{ 
"everfi_commons":{ 
    "info" : { 
       "projTotal" : "everfi_Commons", 
     "company" : "Everfi", 
     "name" : "Commons", 
       "type" : "ipad", 
     "description" : "this product, bla bla bla bla bla", 
     "folder": "everfi_commons", 
       "thumbProjName": "COMMONS", 
       "thumbDescription" : "bla bla bla bla bla" 
    }, 
    "images" : { 
     "image_1" : "image one url", 
     "image_2" : "image two url", 
     "image_3" : "image three url", 
     "image_4" : "image four url" 
    } 
}, 
"project_two":{ 
    "info" : { 
       "projTotal" : "project_two", 
     "company" : "Everfi", 
     "name" : "Commons", 
       "type" : "html5", 
     "description" : "this product, bla bla bla bla bla", 
     "folder": "project_two", 
       "thumbProjName": "COMPANY 2", 
       "thumbDescription" : "bla bla bla bla bla" 
    }, 
    "images" : { 
     "image_1" : "image one url", 
     "image_2" : "image two url", 
     "image_3" : "image three url", 
     "image_4" : "image four url", 
       "image_5" : "image five url" 
    } 
} 
} 

내가 개체로 매우 구체적인 부분에 액세스하는 방법을 알고,하지만 내가 무엇을 궁금하네요 everfi_commons.images에 들어갈 수있는 방법이 있다면 나열된 이미지의 수와 상관없이 모든 이미지 URL을 가져 와서 div에 넣을 수 있습니까?

도움을 주셔서 감사합니다.

답변

1

확실히. 먼저 객체로 JSON을 구문 분석하고 everfi_commons.images를 통해 다음 반복 다음 JSON은 AJAX 호출을 통해 검색하면 서버가 올바른을 보내는 경우 jQuery를 자동으로 그렇게 할 것 같은

var data = $.parseJSON(...); 
for(image in data.everfi_commons.images) { 
    alert(data.everfi_commons.images[image]); // or whatever you want 
} 

다음 당신도 $.parseJSON 필요하지 않습니다 응답에서 Content-Type.

+0

cooooooolll, 고맙습니다! – loriensleafs