Friday, 15 August 2014

javascript - Invalid character error when parsing JSON -


I am trying to parse JSON data from an external json file (an array). But not returning the note I am getting an error (f12) invalid character . What can be the problem here? How can I fix this?

  var myAr; $ .ajax ({url: 'test.json'}) done (function (d) {myAr = JSON.parse (d); // invalid character});  

External file:

  [["parrot", "green"], ["swan", "white"]]  < While retrieving JSON via AJAX using jQuery it will automatically deserialize for you. Calling  JSON.parse ()  Again the resultant object will be seen as an error as you have seen in your code  d  is already an object in which all properties returned from the request Are ready for your use: 

  $ Ajax ({url: 'test Json'}). Done (function (d) {console.log (d); // shows the object back});  

No comments:

Post a Comment