正在分析JSON字符串(或者它是XML?)



我有一个XML文件需要传递。

http://mckay.canvashost.com:8080/opentripplanner-api webapp/ws/transit/stopTimesForStop?id=27833&startTime=1361784386000&extended=true&references=真正的

我使用PHP的CURL将其加载到页面中:

$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格式的吗?

输出是一个xml字符串。尝试使用SimpleXml:提供的php的xml功能

SimpleXml

一旦成功解析字符串,就可以像数组一样迭代其节点

foreach ($xmlElement as $node) {
echo $node->attributeName;
}

相关内容

最新更新