美文网首页
JsonPath基本使用

JsonPath基本使用

作者: 运动书生 | 来源:发表于2019-03-04 20:22 被阅读0次

    JsonPath is to JSON what XPATH is to XML, a simple way to extract parts of a given document. JsonPath is available in many programming languages such as Javascript, Python and PHP.

    jsonpath依赖

           <json-path.version>2.3.0</json-path.version>
           <dependency>
                <groupId>com.jayway.jsonpath</groupId>
                <artifactId>json-path</artifactId>
            </dependency>
    

    jsonpath使用

            List<String> authors = JsonPath.read(json, "$.store.book[*].author");
    

    直接生成JsonNode

    static {
            Configuration.setDefaults(new Configuration.Defaults() {
    
                private final JsonProvider jsonProvider = new JacksonJsonNodeJsonProvider();
                private final MappingProvider mappingProvider = new JacksonMappingProvider();
    
                @Override
                public JsonProvider jsonProvider() {
                    return jsonProvider;
                }
    
                @Override
                public MappingProvider mappingProvider() {
                    return mappingProvider;
                }
    
                @Override
                public Set<Option> options() {
                    return EnumSet.noneOf(Option.class);
                }
            });
        }
    
    
            JsonNode authors = JsonPath.read(json, "$.store.book[*].author");
    
    

    参考文档:
    https://blog.csdn.net/koflance/article/details/63262484

    相关文章

      网友评论

          本文标题:JsonPath基本使用

          本文链接:https://www.haomeiwen.com/subject/rigiuqtx.html