duandan9680 2015-01-02 11:44
浏览 97
已采纳

php中的json_decode用于web服务url(url给出数据)

My problem is I have one web-service which return the data in the json format I am using the following code to access the data

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

I am getting the error can't open url. I am not getting the problem.Somehow I am not able to access the json_decode data and there are some function which are using the same functionality and the those are able to access the data

Thanks in advance

  • 写回答

2条回答 默认 最新

  • dongmi1663 2015-01-02 12:01
    关注

    First check the url is correct and valid, And try to check for the errors on error.log for the errors on file_get_contents

    Note: file_get_contents() returns the file in a string, starting at the specified offset up to maxlen bytes. On failure, file_get_contents() will return FALSE.

    if the above condition is true check with this,

    Try printing json data

    var_dump(json_decode($datas, true));

    This may help you,

    V.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效