如何使用json.simple和java在JSONArray中的每个JSONObject之间添加新行

如何使用json.simple和java在JSONArray中的每个JSONObject之间添加新行,java,json,file-format,Java,Json,File Format,我试图使用json.simple库中的JSONArray对象写入json文件。我遇到的问题是,文件的格式如下所示: [{"artist_name":"test1","year":0,"album_name":null,"song_name":"test1"},{"artist_name":"test1","year":0,"album_name":null,"song_name":"test1"}] 当我希望格式如下所示: [{"artist_name":"test1", "year":0,

我试图使用json.simple库中的JSONArray对象写入json文件。我遇到的问题是,文件的格式如下所示:

[{"artist_name":"test1","year":0,"album_name":null,"song_name":"test1"},{"artist_name":"test1","year":0,"album_name":null,"song_name":"test1"}]
当我希望格式如下所示:

[{"artist_name":"test1",
"year":0,
"album_name":null,
"song_name":"test1"},

{"artist_name":"test1",
"year":0,
"album_name":null,
"song_name":"test1"}]
这就是我的代码现在的样子:

        FileWriter filewriter = new FileWriter("filesystem.json");

        JSONObject newo = new JSONObject();
        newo.put("song_name", "test1");
        newo.put("artist_name", "test1");
        newo.put("album_name", null);
        newo.put("year", 0);

        arr.add(newo);
        filewriter.write(arr.toJSONString());
        filewriter.flush();
        filewriter.close();

您不需要向代码中添加任何内容。当您从某处检索Json时,它总是这样。如果您想以您描述的方式查看它,请尝试google json查看器,它可能会有所帮助。

您不需要在代码中添加任何内容。当您从某处检索Json时,它总是这样。如果您想以您描述的方式查看它,请尝试google json查看器,它可能会有所帮助