返回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