PHP中的json_decode [英] json_decode in php

查看:135
本文介绍了PHP中的json_decode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对这个json文件使用json_decode,但是出了点问题.几天前工作正常,但现在返回NULL.

I want to use json_decode to this json file but something is going wrong. It was working fine a few days ago but now returns NULL.

<?php 

$url = 'http://opendata.diavgeia.gov.gr/api/decisions?org=eot&output=json'; 


function works2($url) 
{ 
   $opts = array( 
     'http'=>array( 
       'method'=>"GET", 
       'header'=>"Connection:Keep-Alive\r\nAccept:*/*\r\n" 
     ) 
   ); 

   $context = stream_context_create($opts); 
   $retstr = file_get_contents($url,false,$context); 
   return $retstr; 
} 


var_dump(json_decode(works2($url)));
?>

有人可以帮我吗?

推荐答案

我使用了JSON验证程序,并且该网址似乎提供了无效的JSON

I used a JSON validator and the url seems to provide an INVALID JSON

尝试使用jsonList在此处验证URL http://jsonlint.com/

try using jsonList to validate the URL here http://jsonlint.com/

我知道

 Parse error on line 822:
 ...         "subject": "Ματαίωση του πρόχει
 -----------------------^
 Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

如果URL提供了正确的JSON字符串,则您的代码应该可以使用.

If the URL provides a proper JSON string your code should work.

这篇关于PHP中的json_decode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆