0

Code:

var jsonTest = {};
var testjson = ["xxxx.jpg","xxx.jpg","xxx.jpg"];
jsonTest = JSON.parse(testjson);

Error message:

Unable to parse JSON string.

However, when I test this in a JSON validator, it tells me that it is correct JSON.

11
  • 3
    It's not a string, it's an array! This makes no sense at all? Commented Apr 20, 2014 at 16:23
  • it's a JSON Array , see here jsonlint.com Commented Apr 20, 2014 at 16:25
  • 1
    JSON is a dataformat used for strings, there's no such thing as a JSON array / JSON object, you're confused. Commented Apr 20, 2014 at 16:27
  • Right, got you. Sorry - but what is the point of JSON.parse, sightly confused now on what it is used for Commented Apr 20, 2014 at 16:30
  • It's used to parse strings that are valid JSON Commented Apr 20, 2014 at 16:30

1 Answer 1

3

testjson is already a valid javascript array, there is no need to parse it.

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

1 Comment

It's actually not JSON at all, and it's not an object, it's a regular javascript array.

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.