0

我目前有一个脚本,可以在这里找到:http: //ddelay.co.uk/bus/find_services2.php

使用以下代码:

<?php
include('simple_html_dom.php');
$service = $_GET["stop"];
$debug = $_GET["debug"];

$url = $service;
if($debug === "yes"){
echo "URL IS: " . $url . "\n";
}

$search = array('?', ' ', '.asp&');
$replace = array('&', '+', '.asp?');

$url2 = str_replace($search, $replace, $url);
if($debug === "yes"){
echo "REPLACEMENTS: ". $url2 . "\n";
}
$end = "http://tsy.acislive.com" . $url2 . '&showall=1';
if($debug === "yes"){
echo "FINAL URL: ". $end;
}

$html = file_get_html($end);

$ret = $html-> getElementsByTagName('table');

print($ret);
?>

例如将从 tsy.acislive.com 拉表(例如:http ://ddelay.co.uk/bus/find_services2.php?stop=/web/public_service_stops.asp?service=22?operatorid=36?systemid =30?goingto=伍德豪斯)

然后我希望能够将此表转换为 JSON 数据以在我的应用程序中使用。不幸的是,我尝试过 PHP 的函数 JSON_encode($ret); 但不幸的是,失败了。有人知道我如何将使用 Simple-Dom-Parser php 提取的这个表转换为 Json Data

4

1 回答 1

0

如果你想转换成 JSON,你应该json_encode 这样做。这是一个非常易于使用的功能。如果您遇到问题,那将有一个潜在的原因。

试试这些来找出你的数据是什么样子的:

var_dump($html);
var_dump($ret);

从 PHP 手册中,传递给的值json_encode Can be any type except a resource.,所以如果它失败了,我只能假设你没有传递正确的数据。

发布这些var_dump电话的结果,我会为您提供解决方案。

于 2013-11-15T22:51:08.727 回答