Skip to content
Advertisement

Can’t parse JSON to Javascript object

I have this HTML box:

JavaScript

Event onchange() implementation:

JavaScript

But when onchange() event is fired I get on this row:

JavaScript

This error:

SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data

return JSON.parse( data + “” );

Any idea why I get error above?

Advertisement

Answer

In your case you don’t need use parseJSON, because d is Object,

JavaScript

Example

When the data attribute is an object (starts with ‘{‘) or array (starts with ‘[‘) then jQuery.parseJSON is used to parse the string; it must follow valid JSON syntax including quoted property names. If the value isn’t parseable as a JavaScript value, it is left as a string.

$.data

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement