2

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`
}]
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.com Commented Sep 23, 2010 at 14:36
  • Thanks i will check that out.I was also thinking the same Commented Sep 23, 2010 at 19:37

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

3 Comments

The OP probably gets above thingadongdong as a string in JSON, which he wants to be converted to a real object (or array, in this case).
then it is required to use eval of course. I will edit my code.
No, it is not required and could even be dangerous (malicious code injection). Use a JSON parser instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.