Query a JSONObject in java

后端 未结 6 1723
鱼传尺愫
鱼传尺愫 2020-11-27 06:12

I was wondering if somewhere out there exists a java library able to query a JSONObject. In more depth I\'m looking for something like:



        
6条回答
  •  孤街浪徒
    2020-11-27 07:13

    While not exactly the same, Jackson has Tree Model representation similar to Gson:

    JsonNode root = objectMapper.readTree(jsonInput);
    return root.get("data").get("data2").get("value").asText();
    

    so you need to traverse it step by step.

    EDIT (August 2015)

    There actually is now (since Jackson 2.3) support for JSON Pointer expressions with Jackson. So you could alternatively use:

    return root.at("/data/data2/value").asText();
    

提交回复
热议问题