0
私は自分のjson構造を持っていますが、現時点では何をしようとしていますか、独自の値で新しいフィールドを挿入しています。 php。これまで私は持っている:jsonをphpで挿入しようとしています
//read the json file contents
$jsondata = file_get_contents('sleaderboard.json');
//convert json object to php associative array
$outdata = json_decode($jsondata, true);
$encdata = json_encode($indata);
$uname = $_POST["username"];
$indata = $uname . '{' . $encdata . '}';
file_put_contents('sleaderboard.json', $indata);
?>
ほとんどのように思えるが、古いデータを削除する。誰か助けを得た? PS:$ indataは、コード内で先に収集された投稿を通過する要素です。
{
"clarke": {
"name": "clarke",
"comment": "comments test",
"score": 6
},
"sam":
{
"name": "sam",
"comment": "insert regular comment here",
"score": 0
},
"test":
{
"name": "test",
"comment": "boring, normal, extremely generic comment",
"score": 7
}
}
は、手でJSONを行うだけで、ファイルを取得し、デコード、配列、エンコードの内側に新しい要素をプッシュし、ファイル – Ghost
の内側に入れません'$ outdata'を保存してください。 –