{"before":null,"after":{"ID":"Bw==","NAME":"Product 3","DESCRIPTION":"Description 3","WEIGHT":"FkQ="},"source":{"version":"1.6.4.Final","connector":"oracle","name":"oracle_logminer","ts_ms":1686274678794,"snapshot":"true","db":"ORA11G","sequence":null,"schema":"C##TEST123","table":"PRODUCTS","txId":null,"scn":"2202609","commit_scn":null,"lcr_position":null},"op":"r","ts_ms":1686274678794,"transaction":null}将上面json中间 after 对应的json完整提取,使用java代码
时间: 2023-07-08 08:48:28 浏览: 408
可以使用以下 Java 代码来提取中间的 `after` JSON:
```java
import com.google.gson.*;
public class JsonParserExample {
public static void main(String[] args) {
String json = "{\"before\":null,\"after\":{\"ID\":\"Bw==\",\"NAME\":\"Product 3\",\"DESCRIPTION\":\"Description 3\",\"WEIGHT\":\"FkQ=\"},\"source\":{\"version\":\"1.6.4.Final\",\"connector\":\"oracle\",\"name\":\"oracle_logminer\",\"ts_ms\":1686274678794,\"snapshot\":\"true\",\"db\":\"ORA11G\",\"sequence\":null,\"schema\":\"C##TEST123\",\"table\":\"PRODUCTS\",\"txId\":null,\"scn\":\"2202609\",\"commit_scn\":null,\"lcr_position\":null},\"op\":\"r\",\"ts_ms\":1686274678794,\"transaction\":null}";
JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(json).getAsJsonObject();
JsonObject afterObject = jsonObject.getAsJsonObject("after");
System.out.println(afterObject.toString());
}
}
```
输出结果为:
```
{"ID":"Bw==","NAME":"Product 3","DESCRIPTION":"Description 3","WEIGHT":"FkQ="}
```
阅读全文