php修改json数据的方法:首先从文件中读取数据到php变量;然后把json字符串转成php数组;最后通过“file_put_contents(text.json,$json_strings);”方法修改json数据即可。
推荐:《php视频教程》
php 读写json文件、追加、修改json
// 追加写入用户名下文件$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);//写入
以上就是php如何修改json数据的详细内容。