Print JSON with PHP, without making multiple roots and making it pretty

后端 未结 1 1622
别跟我提以往
别跟我提以往 2021-01-25 23:40

I have a .txt file where I have list of Windows 8 apps, written in JSON, that is being used in an Windows 8 app. I want to be able to have an online form, where I can input a ne

相关标签:
1条回答
  • 2021-01-26 00:20

    Don't use FILE_APPEND. You're already appending the new entry to $content, so you need to rewrite the file completely, not add the new array after the old one.

        $content = json_decode( file_get_contents( $savePath ) , true );
        //add the new data
        $content[] = array( 
            'backgroundImage' => $bi ,
            'description' => $ad,
            'extraImages' => $ei,
            'group' => array('backgroundImage' => $gbi, 'description' => $gd, 'groupImage' => $gi, 'key' => $gk, 'shortTitle' => $gst, 'title' => $gt,),
            'teacherReview' => $tr,
            'rating' => $rating,
            'shortTitle' => $st,
            'tileImage' => $ti,
            'title' => $title
            );
    
        //encode the new data
        $content_json = json_encode($content);
        file_put_contents( $savePath , $content_json );
    
    0 讨论(0)
提交回复
热议问题