PHP解析JSON和XML方法

 一、JSON

$r = json_decode("json数据"); 
$result  =  $r->result;   //解析后的数据,以数组形式保存到r里面了,需要通过->符号访问,不能用[]访问

json解析后,虽然是类似数组形式,但是需要通过->符号访问,不能通过[]形式访问,同样可以做遍历等操作

二、XML


//==主程序执行
function simplest_xml_to_array($xmlstring) {
    return json_decode(json_encode((array) simplexml_load_string($xmlstring)), true);
}
$data	=	simplest_xml_to_array("XML文档"); 

变量data会返回为常规数组

原文地址:https://www.cnblogs.com/phpyangbo/p/php-json-xml.html