2

Hi I have this code to parse JSON on JQUERY

var json_text2 = $.parseJSON('{"data":[["1340650436","2.00000"],["1340736844","4.00000"]],"label":"Waist Size (cm)"},{"data":[["1340736861","3.40000"],["1340650514","4.00000"]],"label":"Arm Size (Inch)","yaxis":"2"}');

BUT I got this error on Firebug

JSON.parse: unexpected non-whitespace character after JSON data
3
  • 6
    Your object looks like {...},{...}. That's invalid JSON. You probably want [{..},{..}]. Commented Jun 27, 2012 at 14:47
  • that looks like an answer to me? Commented Jun 27, 2012 at 14:47
  • 2
    try running it through json lint Commented Jun 27, 2012 at 14:48

1 Answer 1

5

A valid JSON string needs to be a single object or an array of objects. Wrap your objects in array brackets []:

var json_text2 = $.parseJSON('[{"data":[["1340650436","2.00000"],["1340736844","4.00000"]],"label":"Waist Size (cm)"},{"data":[["1340736861","3.40000"],["1340650514","4.00000"]],"label":"Arm Size (Inch)","yaxis":"2"}]');
Sign up to request clarification or add additional context in comments.

4 Comments

Or a string actually or array of strings as well. :)
Tested that JSON on chris.photobooks.com/json/default.htm. Its still saying invalid JSON.
@Dev, it checks out on jsFiddle on Chrome: jsfiddle.net/jackwanders/ZBad9. Works fine on your link too. Did you include the outer single quotes, because that's not part of the actual JSON string
Thanks YOU! solved the problem now! :) I was having on my code [json_text2] now I just removed the '[' and ']' and place it on the parseJSON :) Thanks a lot!!!

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.