2014-02-11 2 views
0

와 JSON 객체를 읽어보십시오. 다음을 시도했습니다 :내가이 JSON 개체가 jQuery를

var obj = jQuery.parseJSON(json_object); //json object 
alert(obj.nodes.items[0].icon); //Uncaught TypeError: Cannot read property 'items' of undefined 
+0

확인 당신은 유효한 json이있다, 당신은 이것을 시도 할 수있다 : http://www.freeformatter.com/json-formatter.html –

답변

1
var items; 
items = obj.Master.nodes.event.items; 

alert(items[0].icon); 

items 결과를 배열에

올바른 jQuery.parseJSON가 실패하지 않으면 선도적 인 {와 후행 두}

json_object = '{ "Master": { 

// 
// 
// 

} }'; 

누락로 JSON이 잘못 유의하십시오. 여기 JSON의

1

JSON은 "마스터"라는 단일 키를 정의합니다. 시도 :

alert(obj.Master.nodes.items[0].icon); 
+0

시도하고있다. :'정의되지 않은 속성 0을 읽을 수 없다. ' –

+0

@ free4ride 권리가있다 - 항목이있다. 노드의 이벤트 키 아래에. – mmigdol

1
console.log(obj.Master.nodes.event.items[0].icon) 

체크 구조 : 당신이 당신의 JSON을 노드 상속을