官术网_书友最值得收藏!

How to do it...

You need to perform the following steps to try this recipe:

  1. 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
}
]
}
}
  1. 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);
}
}
}
  1. The execution of this code prints the following:
profile: [{"id":1},{"id":2},{"id":3}]

主站蜘蛛池模板: 云南省| 法库县| 通辽市| 武清区| 繁峙县| 北宁市| 沧州市| 凯里市| 岳阳市| 林甸县| 开原市| 普兰店市| 四子王旗| 灵武市| 多伦县| 天门市| 沁水县| 白朗县| 东乌珠穆沁旗| 阿瓦提县| 龙州县| 沁源县| 乳源| 江永县| 永寿县| 东乡县| 盐源县| 麦盖提县| 扎鲁特旗| 绍兴县| 大英县| 鸡泽县| 松江区| 新田县| 福泉市| 天等县| 临清市| 五台县| 财经| 南涧| 巴彦县|