我有name.json文件:如何將數組追加到已有數組的json文件中?
[
{"name" : "James",
"Surname" : "Bond"
},
{
"name" : "Abc",
"Surname" : "Xyz"
}]
現在我要到另一個陣列添加到該現有文件:
[
{"name" : "Brad",
"Surname" : "Pitt"
},
{
"name" : "Angelina ",
"Surname" : "Jolie "
}
]
結果應該是這樣的:
[
{"name" : "James",
"Surname" : "Bond"
},
{
"name" : "Abc",
"Surname" : "Xyz"
},
{"name" : "Brad",
"Surname" : "Pitt"
},
{
"name" : "Angelina ",
"Surname" : "Jolie "
}
]
但我有這樣的結果:
[
{"name" : "James",
"Surname" : "Bond"
},
{
"name" : "Abc",
"Surname" : "Xyz"
}]
[
{"name" : "Brad",
"Surname" : "Pitt"
},
{
"name" : "Angelina ",
"Surname" : "Jolie "
}
]
如何解決這個問題?
我正在向這樣的文件附加數據。
void writeJson(JSONArray jsonDataObject){
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
writer.writeValue(new File("/home/cp/name.json"), jsonDataObject);
}
後這裏的代碼 – Vel
好了,不要在你的文本中插入支架編輯。或者你有沒有機會使用IDE和編程?因爲我們不知道。 –
事情是,我想每次追加JSONArry到磁盤上的文件,我正在使用eclipse。 – Bond