- Jakarta EE Cookbook
- Elder Moraes
- 115字
- 2021-06-24 16:12:38
How to do it...
You need to perform the following steps to try this recipe:
- First, we define a JSON message to represent the User object:
{
"user": {
"email": "elder@eldermoraes.com",
"name": "Elder",
"profile": [
{
"id": 1
},
{
"id": 2
},
{
"id": 3
}
]
}
}
- Now, we create a method to read it and print the values we want:
public class JPointer {
public static void main(String[] args) throws IOException{
try (InputStream is =
JPointer.class.getClassLoader().getResourceAsStream("user.json");
JsonReader jr = Json.createReader(is)) {
JsonStructure js = jr.read();
JsonPointer jp = Json.createPointer("/user/profile");
JsonValue jv = jp.getValue(js);
System.out.println("profile: " + jv);
}
}
}
- The execution of this code prints the following:
profile: [{"id":1},{"id":2},{"id":3}]
推薦閱讀
- R語言經(jīng)典實例(原書第2版)
- Unity 2020 Mobile Game Development
- GitLab Repository Management
- Learning AndEngine
- FFmpeg入門詳解:音視頻原理及應(yīng)用
- Mastering Google App Engine
- H5頁面設(shè)計:Mugeda版(微課版)
- 焊接機器人系統(tǒng)操作、編程與維護
- Web性能實戰(zhàn)
- Hands-On Full Stack Development with Spring Boot 2.0 and React
- OpenCV with Python Blueprints
- 軟件工程與UML案例解析(第三版)
- Android高級開發(fā)實戰(zhàn):UI、NDK與安全
- Spring Boot從入門到實戰(zhàn)
- Splunk Developer's Guide(Second Edition)