我有一个数组
Array
(
[1] => Array
(
[title] => Graslei BVBA
[address] => Belgium Bent
)
[2] => Array
(
[title] => Red Poppy SPRL
[address] => Belgium 4900 Spa
)
[3] => Array
(
[title] => Loula Bee
[address] => Belgium Liege
)
)
我将JavaScript函数中的数组传递为
json_encode
。请任何人都可以帮助我阅读JavaScript中的JSON。
var info = {
"1":{"title":"Graslei BVBA","address":"Belgium Bent"},
"2":{"title":"Red Poppy SPRL","address":"Belgium 4900 Spa"},
"3":{"title":"Loula Bee","address":"Belgium Liege"}
}
我希望从上方读取地址。
预先感谢您的帮助。
最佳答案
var info = {"1":{"title":"Graslei BVBA","address":"Belgium Bent"},"2":{"title":"Red Poppy SPRL","address":"Belgium 4900 Spa"},"3":{"title":"Loula Bee","address":"Belgium Liege"}};
/*
* info[number][string]
*/
info[1] // Object {title: "Graslei BVBA", address: "Belgium Bent"}
info[1]["address"] // "Belgium Bent"
// for
for (var i in info) (function(title, address) {
console.log(title, address); // print title and address
}(info[i]["title"], info[i]["address"]));
看样品http://jsfiddle.net/DHeUL/