PHP解析Json文档
PHP解析Json文档详细介绍
解析 Json 文件
代码
使用函数 json_decode() , file_get_contents()
首先 json_decode() 这个函数需要传递至少一个参数
需要用 file_get_contents() 来把文件转换成字符串
$string = file_get_contents("shuJu.json");
然后把字符串内容放到 json_decode() 参数
$shuJu = json_decode($string);
拿到结果
echo $shuJu->neiRong;
// 结果就是 内容
文件 shuJu.json
{
"neiRong":"内容"
}