json_decode in php for the webservice url (url 给出了数据)

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

我的问题是我有一个网络服务,其中 return 数据采用 json 格式 我正在使用以下代码访问数据

 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]]}

我收到无法打开的错误 url。 我没有得到 problem.Somehow 我无法访问 json_decode 数据,并且有一些功能使用相同的功能并且能够访问数据

提前致谢

运行 使用 url 和使用 file_get_content 获取数据是不同的事情。 1) 当你在 url 中 运行 时,它会给你由 PHP

处理的输出

2) 当您执行 file_get_content 时,它将为您提供该文件中的代码。你应该使用 curl 来满足你的需求

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

上的错误

注意:file_get_contents() returns 字符串中的文件,从指定的偏移量开始,最多 maxlen 字节。失败时,file_get_contents() 将 return FALSE。

如果上述条件成立,请用这个检查,

尝试打印 json 数据

var_dump(json_decode($datas, true));

这可能对你有帮助,

V.