gpt4 book ai didi

javascript - 在javascript中读取json

转载 作者:行者123 更新时间:2023-11-30 10:31:17 25 4
gpt4 key购买 nike

我有一个数组

     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"}};

$('P').append(info["1"].address);

你甚至可以这样做:

var addr = info["1"]["address"];

JSFiddle:http://jsfiddle.net/infiniteloops/2sTY6/

关于javascript - 在javascript中读取json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16829703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com