2
我有一個需要傳遞的XML文件。解析JSON字符串(還是XML?)
我使用PHP的捲曲將其加載到頁面:
$url = "http://mckay.canvashost.com:8080/opentripplanner-api-webapp/ws/transit/stopTimesForStop?id=27833&startTime=1361784386000&extended=true&references=true";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$xml = curl_exec($ch);
curl_close($ch);
echo htmlentities($xml, ENT_QUOTES, "UTF-8");
輸出是一個JSON文件,我沒想到。無論如何,我繼續使用JSON工作,但似乎無法解析它。
我原以爲這會工作:
$obj=json_decode($xml);
echo $obj[stopTime][0][phase];
隨着 '出發' 的結果。我在這方面花了很長時間,但卻無法輸出任何內容。
任何幫助?任何人都知道它從XML文件切換到JSON格式?
你到底把解壓出來的這個數據? – Blender 2013-02-26 04:03:56
試試'json_decode($ xml,true);'。 [PHP文檔](http://www.php.net/manual/en/function.json-decode.php)。 – Passerby 2013-02-26 04:08:15
該鏈接爲我返回一個XML文件。是什麼讓你認爲它是JSON? – cdmckay 2013-02-26 04:20:52