This is my JSON: (This is AJAX response data)
{"id":"1","code":"43","doc":"{\"date\":\"2016\",\"name\":\"NAME1\",\"id\":\"7\"}"}
I would like to parse this JSON with jQuery:
var obj = jQuery.parseJSON(data);
This is doc: console.log(obj.doc);
{\"date\":\"2016\",\"name\":\"NAME1\",\"id\":\"7\"}
But how do I refer to the "name"? I do not refer to obj.doc.name, because the "name" is not element on the object.
obj.docis a string containing JSON. You'd need to applyJSON.parse(obj.doc)again. Better however would be to fix the code that generates the JSON to not double encode your data.docis itself JSON, so you'll need to parse it. Something likevar obj = jQuery.parseJSON(data); obj.doc = jQuery.parseJSON(obj.doc);