时间:2021-07-01 10:21:17 帮助过:3人阅读
实例如下所示:
// 追加写入用户名下文件
$code="001";//动态数据
$json_string = file_get_contents("text.json");// 从文件中读取数据到PHP变量
$data = json_decode($json_string,true);// 把JSON字符串转成PHP数组
$data[$code]=array("a"=>"as","b"=>"bs","c"=>"cs");
$json_strings = json_encode($data);
file_put_contents("text.json",$json_strings);//写入
//修改
$json_string = file_get_contents("text.json");// 从文件中读取数据到PHP变量
$data = json_decode($json_string,true);// 把JSON字符串转成PHP数组
$data["001"]["a"]="aas";
$json_strings = json_encode($data);
file_put_contents("text.json",$json_strings);//写入相关推荐:
如何使用python读写json文件
javascript读写json示例_javascript技巧
js读写json文件实例代码_javascript技巧
以上就是php如何读写json文件及修改json方法的详细内容,更多请关注Gxl网其它相关文章!