2011-03-14 10 views
4

다음 JSON 데이터가 클라이언트로 전송됩니다. 어떻게 든 데이터를 추출해야 루프를 통해 모든 값을 얻을 수 있습니다. & 카운트 값. jQuery을 활용클라이언트 측에서 Json 데이터 추출

{ 
"summarydata": { 
    "rows": [ 
     { 
     "name": "Cisco0 Webinar US", 
     "count": "1" 
     }, 
     { 
     "name": "Resource Nation CC", 
     "count": "1" 
     }, 
     { 
     "name": "test", 
     "count": "10" 
     }, 
     { 
     "name": "test", 
     "count": "2" 
     }, 
     { 
     "name": "Vendor Seek", 
     "count": "1" 
     } 
    ] 
    } 
} 

$.extend($.jgrid.defaults, 
     { datatype: 'jsonstring' }, 
     { ajaxGridOptions: { contentType: "application/json", 
     success: function (data, textStatus) { 

      if (textStatus == "success") { 
       var thegrid = $("#BuyBackGrid")[0]; 
       thegrid.addJSONData(data.data); 
       var summaryresult = $.parseJSON(data.summarydata.rows[0]); 

       alert(summaryresult);// this gives me null 
       alert(data.summarydata.rows[0].name); //this gives me first name element which is "Cisco0 Webinar US" in my case. 

      // alert($.parseJSON(data).summarydata.rows[0].name);    

          } 
     } //end of success 
     }//end of ajaxGridOptions 
    }); 
+2

어떤 언어 ?? –

+0

JSON 라이브러리에서 라이브러리를 사용하고 있습니까? – bensiu

+0

나는 ajax 호출을 만들고 JSON 데이터를 클라이언트에 반환하기 위해 asp.net 처리기를 사용하고있다. 응답. 추가 ("summarydata", summarytoken); – user659469

답변

6

...

$.getJSON() 기능은 로컬 JSON 파일을 구문 분석하고 객체로서 돌려줍니다.

$.getJSON("myJSON.js", function(json){ 
    alert(json.summarydata.rows[0].name); 
}); 

은 또한 단지 자바 스크립트에 대한 JSON library을 (객체는 가장 최근의 브라우저에서 표준)를 사용하여이 작업을 수행 할 수 있습니다.

alert(JSON.parse(myJSONString).summarydata.rows[0].name); 
관련 문제