{"id":676,"date":"2022-08-30T15:05:19","date_gmt":"2022-08-30T15:05:19","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/getting-error-while-converting-xml-to-json-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:05:19","modified_gmt":"2022-08-30T15:05:19","slug":"getting-error-while-converting-xml-to-json-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/getting-error-while-converting-xml-to-json-collection-of-common-programming-errors\/","title":{"rendered":"getting error while converting xml to json-Collection of common programming errors"},"content":{"rendered":"<p>I am getting <strong>undefined function<\/strong> error when i am using <code>json_encode()<\/code> function. I need to convert the xml data to json data. The code i am using is :<\/p>\n<pre><code>$xml = simplexml_load_string($retValue);\necho json_encode($xml);\n<\/code><\/pre>\n<p>I also tried this:<\/p>\n<pre><code>$xml = simplexml_load_string($retValue);\n$array = objectsIntoArray($xml);\n$array = json_encode($array);\nprint_r($array);\ndie;\n\nfunction objectsIntoArray($arrObjData, $arrSkipIndices = array())\n{\n\n    $arrData = array();\n    if (is_object($arrObjData)) {\n        $arrObjData = get_object_vars($arrObjData);\n    }\n    if (is_array($arrObjData)) {\n        foreach ($arrObjData as $index =&gt; $value) {\n            if (is_object($value) || is_array($value)) {\n                $value = objectsIntoArray($value, $arrSkipIndices);\n            }\n            if (in_array($index, $arrSkipIndices)) {\n                continue;\n            }\n            $arrData[$index] = $value;\n        }\n    }\n    return $arrData;\n}\n<\/code><\/pre>\n<p>But in this <code>objectsIntoArray()<\/code> and <code>json_encode()<\/code> both are throwing function undefined errors. <code>$retValue<\/code> contains the xml data. I am not able to figure out why i am getting this error. Am i missing something. I am totally new to php and not much aware of it. Please help me regarding this.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:26:45. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am getting undefined function error when i am using json_encode() function. I need to convert the xml data to json data. The code i am using is : $xml = simplexml_load_string($retValue); echo json_encode($xml); I also tried this: $xml = simplexml_load_string($retValue); $array = objectsIntoArray($xml); $array = json_encode($array); print_r($array); die; function objectsIntoArray($arrObjData, $arrSkipIndices = array()) { [&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-676","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/676","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=676"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/676\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}