[英]How to Parse XML into JSON Array?
如何將XML解析為JSON數組?
我發現這個解決方案:
if (!function_exists('xmlToArray')) {
function xmlToArray($xmlInput, $bodyXpath) {
$response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $xmlInput);
$xmlTest = new SimpleXMLElement($response);
$body = $xmlTest - > xpath('//soapenvBody')[0];
$simpleXml = json_decode(json_encode((array) $body), true);
$test = simplexml_load_string($simpleXml['qdeinvokeResponse']['qdereturn']['ns1data']);
return json_decode(json_encode((array) $test), true);
}
}
https://www.ibm.com/developerworks/xml/library/x-xml2jsonphp/
要么
簡單地說, $json = json_encode(simplexml_load_string($xmlString)); $array = json_decode($json,true);
$json = json_encode(simplexml_load_string($xmlString)); $array = json_decode($json,true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.