What is the best way to combine (merge) two JSONObjects
?
JSONObject o1 = {
\"one\": \"1\",
\"two\": \"2\",
\"three\": \"3\"
}
JSONObject
Merge JsonObject(gson)-
JsonObject data = new JsonObject();
data = receivedJsoData.get("details").getAsJsonObject();
JsonObject data2 = new JsonObject();
data2 = receivedJsoData1.get("details").getAsJsonObject();
JsonObject mergedData = new JsonObject();
Set> entries = data1.entrySet(); //will return members of your object
for (Map.Entry entry : entries) {
mergedData.add(entry.getKey(), entry.getValue());
}
Set> entries1 = data2.entrySet(); //will return members of your object
for (Map.Entry entry : entries1) {
mergedData.add(entry.getKey(), entry.getValue());
}