0

JSON ファイルの形式が正しくありません (doc1.json):

{"text":"xxx","user":{"id":96525997,"name":"ss"},"id":29005752194568192}
{"text":"yyy","user":{"id":32544632,"name":"cc"},"id":29005753951977472}
{...}{...}

そして、私はこれを変更する必要があります:

{"u":[
{"text":"xxx","user":{"id":96525997,"name":"ss"},"id":29005752194568192},
{"text":"yyy","user":{"id":32544632,"name":"cc"},"id":29005753951977472},
{...},{...}
]}

PHPファイルでこれを行うことはできますか?

4

2 に答える 2

1
//Get the contents of file
    $fileStr = file_get_contents(filelocation);

//Make proper json
    $fileStr = str_replace('}{', '},{', $fileStr);

//Create new json    
    $fileStr = '{"u":[' . $fileStr . ']}';

//Insert the new string into the file
    file_put_contents(filelocation, $fileStr);
于 2015-05-20T14:28:41.533 に答える