admin管理员组

文章数量:1328597

how to access JSON array elements for the following JSON Code? further how do i calculate the size of the returned object array?

[
{
lastInvAmt: 0
bwHrs: 0
nbwHrs: 0
unbilledAmt: 0
unbilledHrs: 0
dbID: 0`
},{
lastInvAmt: 0
bwHrs: 0
nbwHrs: 0
unbilledAmt: 0
unbilledHrs: 0
dbID: 0`
}]

how to access JSON array elements for the following JSON Code? further how do i calculate the size of the returned object array?

[
{
lastInvAmt: 0
bwHrs: 0
nbwHrs: 0
unbilledAmt: 0
unbilledHrs: 0
dbID: 0`
},{
lastInvAmt: 0
bwHrs: 0
nbwHrs: 0
unbilledAmt: 0
unbilledHrs: 0
dbID: 0`
}]
Share Improve this question asked Sep 23, 2010 at 14:14 BinCodeBinCode 6334 gold badges12 silver badges22 bronze badges 2
  • 2 This is not a valid JSON string; in JSON, every string, whether it represents a key or a value, should be encapsulated in double quotes ("). Also notice the strange backticks after the dbID values. You can test your string with jsonlint. – Marcel Korpel Commented Sep 23, 2010 at 14:36
  • Thanks i will check that out.I was also thinking the same – BinCode Commented Sep 23, 2010 at 19:37
Add a ment  | 

1 Answer 1

Reset to default 2

Why can't you assign it to variable? Or I don't understand anything? :)

edited to work with json string

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?

本文标签: javascriptHow to access JSON Array elements returned from an AJAX responseStack Overflow