Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

通过Fastjson的jsonpath得到的数据与jayway官方JsonPath得到数据不一样 #1030

Closed
markho1024 opened this issue Feb 20, 2017 · 0 comments
Labels
Milestone

Comments

@markho1024
Copy link

markho1024 commented Feb 20, 2017

场景是这样,有一个多层array结构的文档,现在需要获取最底层的array的元素。代码如下

    public static void main(String[] args) {
        String DOC = "{\"books\":[{\"pageWords\":[{\"num\":10},{\"num\":15}]},{\"pageWords\":[{\"num\":20}]}]}";

        //fastjson包
        JSONObject result = JSONObject.parseObject(DOC);
        Object eval = JSONPath.eval(result, "$.books[0:].pageWords[0:]");
        System.out.println(JSONObject.toJSONString(eval));

        //jayway包
        DocumentContext parse = JsonPath.parse(DOC);
        Object read = parse.read("$.books[0:].pageWords[0:]");
        System.out.println(read.toString());
    }

结果:

[[{"num":10},{"num":15}],[{"num":20}]]
[{"num":10},{"num":15},{"num":20}]

两个的path都一样,结果却不同,我需要的下面那种结果,然后fastjson是需要开启什么配置么?

@wenshao wenshao added the bug label Mar 11, 2017
@wenshao wenshao added this to the 1.2.29 milestone Mar 11, 2017
wenshao added a commit that referenced this issue Mar 13, 2017
@wenshao wenshao closed this as completed Mar 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants