这个问题在这里已有答案:
如果我有一个名为lol.json的文件并且其中包含json数据,那么如何使用php将该文件中的数据发送到另一个页面(或同一页面)。
这里有一些有用的线你可以使用:
/* Set the json file directory */
$path = 'your path here';
/* here your json file name */
$jsonfile = 'youjsonfilename';
/* json decode */
$language = json_decode(file_get_contents($path . $jsonfile. '.json'));
然后,如果你的json文件看起来像这样:
{
"test": {
"test1" : "test2",
}
}
你必须用php写这行来打印“test2”,例如:
<?php echo $language->test->test1; ?>