//判断文件是否存在
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?php 2 //判断文件是否存在 3 if(file_exists("login/userinfo.json")){ 4 echo "文件存在"; 5 } 6 else{ 7 echo "文件不存在"; 8 } 9 $filename="login/userinfo.json";
//取得json文件的属性值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 $js=file_get_contents($filename); 2 $js=json_decode($js); 3 echo print_r($js);//打印文件的内容 4 echo $js[0]->username; 5 echo $js[0]->password; 6 $username=$js[0]->username; 7 $pwd=$js[0]->password;
//修改json文件的属性值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 $arr=array("ds","f"); 2 $js[0]->username=$arr[0]; 3 $js[0]->password=$arr[1]; 4 file_put_contents($filename,json_encode($js)); 5 ?> 6 7 json文件的内容:userinfo.json 8 9 [{"username":"saoloo","password":"s"}]