[英]json_decode in php
I want to use json_decode to this json file but something is going wrong. 我想对这个json文件使用json_decode,但是出了点问题。 It was working fine a few days ago but now returns NULL.
几天前工作正常,但现在返回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)));
?>
Could anyone help me? 有人可以帮我吗?
I used a JSON validator and the url seems to provide an INVALID JSON 我使用了JSON验证程序,并且该网址似乎提供了无效的JSON
try using jsonList to validate the URL here http://jsonlint.com/ 尝试使用jsonList在此处验证URL http://jsonlint.com/
I get 我懂了
Parse error on line 822:
... "subject": "Ματαίωση του πρόχει
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
If the URL provides a proper JSON string your code should work. 如果URL提供了正确的JSON字符串,则您的代码应该可以使用。
I don't think json_decode
stopped working for you. 我不认为
json_decode
为您停止工作。 It's rather server response. 而是服务器响应。 Did you print $retstr to make sure it's not empty or broken?
您是否打印$ retstr以确保它不为空或损坏?
works2 result is ok. works2结果还可以。 Maybe the json encoded content is too big or (probably) contains unwanted characters or a malformed sequence.
json编码的内容可能太大,或者(可能)包含不需要的字符或格式错误的序列。 Take a look to default opendata output.
看一下默认的opendata输出。 It is xml format, but far long to download.
它是xml格式,但下载时间很长。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.