{"id":1282,"date":"2022-08-30T15:15:14","date_gmt":"2022-08-30T15:15:14","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/10\/jquery-parsejson-returning-empty-data-structure-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:15:14","modified_gmt":"2022-08-30T15:15:14","slug":"jquery-parsejson-returning-empty-data-structure-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/jquery-parsejson-returning-empty-data-structure-collection-of-common-programming-errors\/","title":{"rendered":"jQuery.parseJSON returning empty data structure-Collection of common programming errors"},"content":{"rendered":"<p>I am having a perplexing issue with data manipulation in JavaScript.<\/p>\n<p>I am using the following code in JavaScript to retrieve data from a PHP\/MySQL source.<\/p>\n<pre><code>var _response = jQuery.ajax({\n    url: \"..\/data\",\n    async: false,\n    type: \"post\",\n    data: oParams\n}).responseText;\n<\/code><\/pre>\n<p>and have confirmed that the contents of _response are<\/p>\n<pre><code>_response = '{\"genus\":[\"Some Data\"],\"series\":[],\"program\":[\"Some Data1\",\"Some Data2\",\"Some Data3\"]}';\n<\/code><\/pre>\n<p>However when doing the following:<\/p>\n<pre><code>var _return = jQuery.parseJSON( _response );\nconsole.log( _return );\n<\/code><\/pre>\n<p>I end up with:<\/p>\n<pre><code>genus: [\"\"]\nprogram: [\"\", \"\", \"\"]\nseries: []\n<\/code><\/pre>\n<p>according to firebug. I have even gone as far as to put the string directly into jQuery.parseJSON() and log the result and still end up with an empty data structure.<\/p>\n<p>Does anyone know what is going on here or what would cause this?<\/p>\n<ol>\n<li>\n<p>There must be something wrong either with your jQuery file or your browser. It works fine for me in jQuery 1.7.1:<\/p>\n<pre><code>&gt; var x = $.parseJSON('{\"genus\":[\"Some Data\"],\"series\":[],\"program\":[\"Some Data1\",\"Some Data2\",\"Some Data3\"]}');\nundefined\n&gt; x[\"genus\"]\n[\"Some Data\"]\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-10 00:14:16. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am having a perplexing issue with data manipulation in JavaScript. I am using the following code in JavaScript to retrieve data from a PHP\/MySQL source. var _response = jQuery.ajax({ url: &#8220;..\/data&#8221;, async: false, type: &#8220;post&#8221;, data: oParams }).responseText; and have confirmed that the contents of _response are _response = &#8216;{&#8220;genus&#8221;:[&#8220;Some Data&#8221;],&#8221;series&#8221;:[],&#8221;program&#8221;:[&#8220;Some Data1&#8243;,&#8221;Some Data2&#8243;,&#8221;Some Data3&#8221;]}&#8217;; [&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-1282","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1282","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=1282"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1282\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}