【发布时间】:2015-01-02 12:04:09
【问题描述】:
我正在使用 PHP 中的 web 服务,下面是代码示例
> if ( $datas=file_get_contents($url) ) return json_decode($datas); > return Array('error' => "Can't open url");
我将上述函数调用的值返回给js页面。但我没有得到 js 中 webservice 调用的值,但总是得到错误值。但是,如果我在浏览器中打开 $url,我会得到以下数据(有效的 json):
{"d":[ [ 5.305,428 ] ] }
由于框架限制,我只能使用 json_decode() 将值返回到我的 js 页面。 我也试过 json_decode($datas,true);但仍然没有帮助。
我还尝试在独立的 php 文件中使用相同的代码: 我收到此错误:当我使用 json_decode($datas)
可捕获的致命错误:stdClass 类的对象无法转换 在 C:\xampp\htdocs\webservice-demo\clientRestTest.php 上的字符串 第 32 行
如果我使用 json_decode($datas,true); 则以下错误;
注意:数组到字符串的转换 C:\xampp\htdocs\webservice-demo\clientRestTest.php 在第 32 行数组
请告诉我如何解决问题。
【问题讨论】:
标签: php json web-services