{"id":1338,"date":"2022-08-30T15:15:42","date_gmt":"2022-08-30T15:15:42","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/10\/how-to-parse-a-json-array-that-contains-multiple-datatypes-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:15:42","modified_gmt":"2022-08-30T15:15:42","slug":"how-to-parse-a-json-array-that-contains-multiple-datatypes-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-parse-a-json-array-that-contains-multiple-datatypes-collection-of-common-programming-errors\/","title":{"rendered":"How to parse a json array that contains multiple datatypes?-Collection of common programming errors"},"content":{"rendered":"<p>I have this json array:<\/p>\n<pre><code>var a = [{\"results\":[{\"id\":\"25\",\"name\":\"John\",\"age\":\"46\"},{\"id\":\"41\",\"name\":\"Sonny\",\"age\":\"31\"}],\"count\":2,\"total\":14}];\n<\/code><\/pre>\n<p>It contains an array called &#8220;results&#8221; and two other variables with numerical values, count and total.<\/p>\n<p>How can i get each of the values of &#8220;results&#8221;, &#8220;count&#8221; and &#8220;total&#8221; from the above array ?<\/p>\n<p>I tried: console.log(a.count);<\/p>\n<p>But it says undefined.<\/p>\n<ol>\n<li>\n<p>First, <strong><em>execute your code<\/em><\/strong> will cause <code>SyntaxError: Unexpected token ILLEGAL<\/code>.<\/p>\n<p>There is an invalid character after <code>age<\/code> between <code>\"age\"\u200c\u200b:\"31\"<\/code>.<\/p>\n<p><strong>Remove that<\/strong>, then <code>a<\/code> is an array, so you get the first element by <code>a[0]<\/code>,<\/p>\n<p>then<\/p>\n<p>get the count by <code>a[0].count<\/code><\/p>\n<p>get the results by <code>a[0].results<\/code><\/p>\n<\/li>\n<li>\n<p>To load results:<\/p>\n<pre><code>console.log(a[0].results);\n<\/code><\/pre>\n<p>To load count:<\/p>\n<pre><code>console.log(a[0].count);\n<\/code><\/pre>\n<p>To load total:<\/p>\n<pre><code>console.log(a[0].total);\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-10 00:45:02. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have this json array: var a = [{&#8220;results&#8221;:[{&#8220;id&#8221;:&#8221;25&#8243;,&#8221;name&#8221;:&#8221;John&#8221;,&#8221;age&#8221;:&#8221;46&#8243;},{&#8220;id&#8221;:&#8221;41&#8243;,&#8221;name&#8221;:&#8221;Sonny&#8221;,&#8221;age&#8221;:&#8221;31&#8243;}],&#8221;count&#8221;:2,&#8221;total&#8221;:14}]; It contains an array called &#8220;results&#8221; and two other variables with numerical values, count and total. How can i get each of the values of &#8220;results&#8221;, &#8220;count&#8221; and &#8220;total&#8221; from the above array ? I tried: console.log(a.count); But it says undefined. First, execute your code will [&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-1338","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1338","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=1338"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1338\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}