返回null,我有这样的json_encode为UTF-8字符集
{"downloads":[
{
"url":"arquivo1.pdf",
"descricao":"árquivo 1"
},
{
"url":"arquivo2.pdf",
"descricao":"arquivo 2"
}
]}
一个JSON文件,我保存使用UTF-8编码通过记事本++它。
然后我得到的文件内容:
function getContent($name)
{
$content = file_get_contents("configs/" . $name . ".json");
$encoded = utf8_encode($content);
return json_decode($encoded);
}
和json_decode
回报null
。
如果我将json文件保存为ANSI,那么它可以工作。但我想将它保存为UTF-8。
如果文件已经在utf-8中,则不必再次对其进行重新编码。 – greut 2012-02-10 17:45:14