我想我们如何解析这样的json使用javacsript直到使用for循环的最后一个元素,我已经完成了这个,但我得到的结果是[对象,对象],[对象,在第一LART对象]和在第二2和如何能JSON数组如何解析此json中的每个值使用for循环在javascript中
[
{
"location": [
{
"building": [
"Default Building"
],
"name": "Default Location"
}
],
"name": "Default Organization"
},
{
"location": [
{
"building": [
"test_loc1_building1",
"test_loc1_building2"
],
"name": "test location1"
},
{
"building": [
"test_loc2_building2"
],
"name": "test location2"
}
],
"name": "test Organization"
}
]
代码我已经在提醒的每一个值在第三[对象,对象]工作是
function orgname()
{
var json = <?php echo $response ?>;
alert(json);
alert(json.length);
for(var i=0; i<json.length; i++)
{
var item = json[i];
alert(item);
}
}
你确定它是JSON(即未解析)吗?它看起来像脚本的纯JS对象。 – 2013-04-11 12:16:28
您似乎警告正确的值。如果您想更好地看到它们,请使用'console.log'而不是'alert'。 – 2013-04-11 12:18:28
我已经使用控制台和基金会,我通过JSON本身形式铬浏览器 – dscxz 2013-04-11 12:19:45