使用 jQuery 从 json_encode 获取值
我从数据库表中的一行中插入了多个带有 json_encode
的(array
)值,现在希望使用 jquery 将它们按顺序回显。
这是我的 PHP 代码的输出:
[{
"guide": null,
"residence": [{
"name_r": "jack"
}, {
"name_r": "jim"
}, {
"name_r": "sara"
}],
"residence_u": [{
"units": ["hello", "how", "what"],
"extra": ["11", "22", "33"],
"price": ["1,111,111", "2,222,222", "3,333,333"]
}, {
"units": ["fine"],
"extra": ["44"],
"price": ["4,444,444"]
}, {
"units": ["thanks", "good"],
"extra": ["55", "66"],
"price": ["5,555,555", "6,666,666"]
}]
}]
我想要 as(output):
杰克
你好
&11
&1,111,111
如何
&22
&2,222,222
什么
&33
&3,333,333,
吉姆
精细
&44
&4,444,444
莎拉
谢谢
&55
&5,555,555
好
&66
&6,666,666
怎么样?
I insert several(array
) value with json_encode
in one row from database table, now want echo they as order with jquery.
This is output from my PHP code:
[{
"guide": null,
"residence": [{
"name_r": "jack"
}, {
"name_r": "jim"
}, {
"name_r": "sara"
}],
"residence_u": [{
"units": ["hello", "how", "what"],
"extra": ["11", "22", "33"],
"price": ["1,111,111", "2,222,222", "3,333,333"]
}, {
"units": ["fine"],
"extra": ["44"],
"price": ["4,444,444"]
}, {
"units": ["thanks", "good"],
"extra": ["55", "66"],
"price": ["5,555,555", "6,666,666"]
}]
}]
I want as(output):
jack
hello
&11
&1,111,111
how
&22
&2,222,222
what
&33
&3,333,333,
jim
fine
&44
&4,444,444
sara
thanks
&55
&5,555,555
good
&66
&6,666,666
How is it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设
console.log
但您可以alert()
或放入 DOM 元素或任何您可以在 jQuery 中执行类似操作的内容(这里是 <一个href="http://jsfiddle.net/nogoodatcoding/erq3d/" rel="nofollow">没有网络部分的小提琴示例 您将在控制台中看到输出)
Assuming
console.log
but you couldalert()
or put into a DOM element or whateveryou could do something like this in jQuery (here's an example fiddle without the network part. You'll see the output in your console)