我需要在一个文件中写入多个json,问题是每次插入插入如下:
{"1":"{\"id\":\"1\"}"**}{**"2":"{\"id\":\"2\"}"**}{**"3":"{\"id\":\"3\"}"}
我需要下面的链可以读取JSON:
{"1":"{\"id\":\"1\"}"**,**"2":"{\"id\":\"2\"}"**,**"3":"{\"id\":\"3\"}"}
我的代码是:
public void writeMci(String mci, String nombreMci) throws Exception{
FileReadWrite a=new FileReadWrite();
JSONObject vjo = new JSONObject();
vjo.put(nombreMci, mci);
try {
BufferedWriter write=new BufferedWriter(new FileWriter("c:\\JSON.json", true));
write.write(vjo.toString());
write.flush();
write.close();
} catch (IOException e) {
//manejar error
}
System.out.print(vjo);
}