小编Ali*_*Ali的帖子

如何使用GSON获得两个json对象之间的差异?

我使用此代码在Android中使用Gson比较两个JSON对象:

String json1 = "{\"name\": \"ABC\", \"city\": \"XYZ\"}";
String json2 = "{\"city\": \"XYZ\", \"name\": \"ABC\"}";

JsonParser parser = new JsonParser();
JsonElement t1 = parser.parse(json1);
JsonElement t2 = parser.parse(json2);

boolean match = t2.equals(t1);
Run Code Online (Sandbox Code Playgroud)

有两种方法可以使用GSON格式的Gson 获取两个对象之间的差异吗?

java android json gson

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

gson ×1

java ×1

json ×1