Home >php教程 >php手册 >Json/Xml 转array数组

Json/Xml 转array数组

WBOY
WBOYOriginal
2016-06-07 11:39:041452browse

Json/Xml 转array数组
//=============================================<br> //本代码并非完美,也许存在不良之处,高手请多指点,请勿吐槽!<br> //作者 小曾 Qq839024615 可加我一起交流<br> //=============================================<br> <br> <br> <br> //----------------------非常不华丽的分割线---------------------//<br> <br> <br> <br> <br> //Json转Array数组<br> $str     = "Json数据";<br> //如<br> /*<br> {<br>   "animals": {<br>     "dog": [<br>       {<br>         "name": "Rufus",<br>         "breed": "labrador"<br>       },<br>       {<br>         "name": "Marty",<br>         "breed": "whippet"<br>       }<br>     ],<br>     "cat": { "-name": "Matilda" }<br>   }<br> }<br> */<br> $json    =  (array)json_decode($str);<br> //(Array)前面加上 将Object转换为数组 诺下级数组无法输出<br> //请给予转换(Array) 例如:  $json[0]= (array)$json[0];<br> print_r($json); //输出数组<br> <br> <br> <br> //----------------------非常不华丽的分割线---------------------//<br> <br> <br> <br> //Xml转Array数组<br> $str     =  "Xml数据";<br> //如<br> /*<br> <animals><dog><name>Rufus</name><breed>labrador</breed></dog><dog><name>Marty</name><breed>whippet</breed></dog><cat></cat></animals><br> */<br> $xml     =  (array)simplexml_load_string($str);<br> <br> //(Array)前面加上 将Object转换为数组 诺下级数组无法输出,<br> //请给予转换(Array) 例如:  $xml[0]= (array)$xml[0];<br> <br> print_r($xml); //输出数组<br> <br> <br> //----------------------非常不华丽的分割线---------------------//<br> <br> //=============================================<br> //本代码并非完美,也许存在不良之处,高手请多指点,请勿吐槽!<br> //作者 小曾 Qq839024615 可加我一起交流<br> //=============================================重要说明:
(Array)前面加上 将Object转换为数组 诺下级数组无法输出,请给予转换(Array) 例如: $xml[0]= (array)$xml[0];
:

Json/Xml 转array数组

Json/Xml 转array数组

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn