0

Why parseJSON fails when I pass a file? My file is in the variable a and after it I just parse using parseJSON

var a = "/android/contents/img/uploads/img_2A0.png";

var result = jQuery.parseJSON(a);

The error which is giving Chrome is: message: "Unexpected token /"

This case raise using droparea.js.

4
  • 6
    Well, the value of a is not valid JSON. jQuery.parseJSON doesn't load data from a URL, it expects the string passed to it to be JSON. I guess you are looking for getJSON: api.jquery.com/jquery.getjson. Commented May 7, 2014 at 23:49
  • 3
    And for that matter. even if it did load data from a URL, why would you think that you could parse a PNG file as JSON? Commented May 7, 2014 at 23:52
  • some behaviour of droparea.js extension Commented May 7, 2014 at 23:56
  • See json.org - please familiarize with the definition/syntax of JSON Commented May 8, 2014 at 0:14

1 Answer 1

4

From docs about parseJSON:

Takes a well-formed JSON string and returns the resulting JavaScript object.

To achieve what you want (getting json from the url) you need to use getJSON. From docs about getJSON:

Load JSON-encoded data from the server using a GET HTTP request.

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

1 Comment

Anyway I manually parsed a like '"' + a + '"'. It is working now. I dont know why droparea needs parse JSON but your solution was tested and working too

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.