需要新建一個json檔案(combined.json)然后將多個json檔案(json1和json2)追加到combined.json。
例子:
Json 1 - 之前創建的 json 檔案
[
{
"name":"John",
"city":"Berlin",
"cars":[
"audi",
"bmw"
],
"job":"Teacher"
}
]
Json2 - 之前創建的 json 檔案
[
{
"name":"Mark",
"city":"Oslo",
"cars":[
"VW",
"Toyata"
],
"job":"Doctor"
}
]
完成品:
Combined.json - 當前創建的 json 檔案
[
{
"name":"John",
"city":"Berlin",
"cars":[
"audi",
"bmw"
],
"job":"Teacher"
},
{
"name":"Mark",
"city":"Oslo",
"cars":[
"VW",
"Toyata"
],
"job":"Doctor"
}
]
uj5u.com熱心網友回復:
Gson gson = new com.google.gson.Gson();
JSONArray combined = gson.fromJson(json1, JSONArray.class);
combined.addAll(gson.fromJson(json2, JSONArray.class));
// verify by looking on the value of: combined.toJSONString()
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/342535.html
