I have a hidden input field like
<input type="hidden" name="product-data" value="{Product: 'Premium', Code: 'ER412', SalesCode: 'SC415', Description: 'Premium Product Details'}" />
on click of a button I am trying to convert this value into JSON object but getting error. Here is my js code
$('.icon-edit').live('click', function(){
var data = $(this).parent().siblings('input').val();
data = jQuery.parseJSON(data); // <--- Here I am getting error
//do something with data
});
Error:
SyntaxError: JSON.parse: expected property name or '}'
JSON property names are strings, and JSON strings are delimited by
"characters.Your property names are identifiers, and where you have string values, you have delimited them with
'. This is fine for a JavaScript object literal, but not for JSON.(You could also delimit the HTML attribute value with
'and use literal"s inside it)