我有以下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
});
Run Code Online (Sandbox Code Playgroud)
利用jQuery ......
该$.getJSON()函数解析本地JSON文件并将其作为对象返回.
$.getJSON("myJSON.js", function(json){
alert(json.summarydata.rows[0].name);
});
Run Code Online (Sandbox Code Playgroud)
你也可以这样做,使用JSON库进行javascript(该对象在大多数浏览器中也是标准的).
alert(JSON.parse(myJSONString).summarydata.rows[0].name);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5211 次 |
| 最近记录: |