{"id":891,"date":"2022-08-30T15:08:54","date_gmt":"2022-08-30T15:08:54","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/jquery-decode-json-object-with-double-quoted-keys-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:08:54","modified_gmt":"2022-08-30T15:08:54","slug":"jquery-decode-json-object-with-double-quoted-keys-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/jquery-decode-json-object-with-double-quoted-keys-collection-of-common-programming-errors\/","title":{"rendered":"jquery decode json object with double quoted keys-Collection of common programming errors"},"content":{"rendered":"<p>I have a script that outputs a json string via json_encode in PHP. The json string consists of<\/p>\n<pre><code>[{\"custId\":\"2\",\"custName\":\"John Inc\"}]\n<\/code><\/pre>\n<p>The PHP script is initiated using<\/p>\n<pre><code>$.getJSON(\"customer.php\", function(data){alert(data + '  ' + data.custName);});\n<\/code><\/pre>\n<p>The response is &#8211;<\/p>\n<pre><code>[object Object] undefined\n<\/code><\/pre>\n<p>Javascript recognises &#8216;data&#8217; as an object but I cannot seem to reference the information using json dotted notation.<\/p>\n<ol>\n<li>\n<p>The <code>data<\/code> object is in an array so you need to access its elements keyed by an index:<\/p>\n<pre><code>alert(data[0].custName);\n<\/code><\/pre>\n<p>Also, I&#8217;d suggest installing firebug (assuming you are already using Firefox) and using <code>console.log<\/code> in lieu of <code>alert.<\/code> Its output is much more detailed and helpful.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:55:04. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have a script that outputs a json string via json_encode in PHP. The json string consists of [{&#8220;custId&#8221;:&#8221;2&#8243;,&#8221;custName&#8221;:&#8221;John Inc&#8221;}] The PHP script is initiated using $.getJSON(&#8220;customer.php&#8221;, function(data){alert(data + &#8216; &#8216; + data.custName);}); The response is &#8211; [object Object] undefined Javascript recognises &#8216;data&#8217; as an object but I cannot seem to reference the information using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-891","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=891"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/891\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}