在 php 中json_decode Web 服务 URL(URL 提供数据)


json_decode in php for the webservice url (url gives the data)

我的问题是我有一个以json格式返回数据的Web服务我使用以下代码访问数据

 if ($datas = file_get_contents($url))
     return json_decode($datas);
 return Array('error' => "Can't open url");
//data when url is accessed in the browser
{"d":[[6.082,245]]}

我收到错误无法打开网址。我没有遇到问题。不知何故,我无法访问json_decode数据,并且有一些功能使用相同的功能,并且那些能够访问数据

的功能

提前致谢

首先检查 url 是否正确和有效,并尝试检查错误时的错误.log错误file_get_contents

注意:file_get_contents() 以字符串形式返回文件,从指定的偏移量开始,一直到 maxlen 字节。失败时,file_get_contents() 将返回 FALSE。

如果上述条件为真,请检查这一点,

尝试打印 json 数据

var_dump(json_decode($datas, true));

这可能会对您有所帮助,

五.

使用 url 运行并使用 file_get_content 获取数据,这两者都是不同的东西。1)当你在url中运行时,它会给你由PHP处理的输出

2)如果你这样做file_get_content它会给你该文件中的代码。你应该使用curl来实现你想要的