書名: 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}]
推薦閱讀
- ServiceNow Application Development
- Python機器學習:數據分析與評分卡建模(微課版)
- Mastering OpenCV Android Application Programming
- 深入實踐Spring Boot
- 實用防銹油配方與制備200例
- Mastering matplotlib
- Python貝葉斯分析(第2版)
- Oracle JDeveloper 11gR2 Cookbook
- C程序設計實踐教程
- R Data Analysis Cookbook(Second Edition)
- Nginx Lua開發實戰
- Hands-On JavaScript for Python Developers
- Windows Phone 8 Game Development
- The Statistics and Calculus with Python Workshop
- AutoCAD基礎教程