php:json

php でjsonのread and write

phpでのjsonファイル読み込みと書き出しの超速レシピ用メモ

$obj = '{ "name": "馬場哲晃",  "gender": "男"}';
$data = json_decode($obj,true);
 
$json = fopen('sample.json', 'w+b');
fwrite($json, json_encode($data));
fclose($json);
$json_string = file_get_contents("sample.json");    //文字列データとしてjsonファイルを読み込み。
$json_string_encoded = mb_convert_encoding($json_string, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN');
$json_decoded = json_decode($json_string_encoded,true);
  • /home/users/2/lolipop.jp-4404d470cd64c603/web/ws/data/pages/php/json.txt
  • 最終更新: 2022/05/31 22:42
  • by baba