Javascript 如何访问从 AJAX 响应返回的 JSON 数组元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3779280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access JSON Array elements returned from an AJAX response
提问by BinCode
how to access JSON array elements for the following JSON Code? further how do i calculate the size of the returned object array?
如何访问以下 JSON 代码的 JSON 数组元素?进一步如何计算返回的对象数组的大小?
[
{
lastInvAmt: 0
bwHrs: 0
nbwHrs: 0
unbilledAmt: 0
unbilledHrs: 0
dbID: 0`
},{
lastInvAmt: 0
bwHrs: 0
nbwHrs: 0
unbilledAmt: 0
unbilledHrs: 0
dbID: 0`
}]
回答by Danil
Why can't you assign it to variable? Or I don't understand anything? :)
为什么不能将它分配给变量?还是我什么都不懂?:)
edited to work with json string
编辑为使用 json 字符串
var ar = eval('[
{
lastInvAmt: 0
bwHrs: 0
nbwHrs: 0
unbilledAmt: 0
unbilledHrs: 0
dbID: 0
},{
lastInvAmt: 0
bwHrs: 0
nbwHrs: 0
unbilledAmt: 0
unbilledHrs: 0
dbID: 0
}]');
Why do you have single quote dbID: 0`. Is it spelling error?
为什么你有单引号 dbID: 0`。是拼写错误吗?