支持DOM风格访问的Java JSON库 [英] Java JSON library that supports DOM-style access

查看:99
本文介绍了支持DOM风格访问的Java JSON库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Java写一个JSON风格的查询引擎,它将从DOM路径查询JSON文档的能力中受益(就像你可以在Javascript中做的那样)。我已经检查了GSON和杰克逊,但似乎都不支持这一点。



任何人都知道任何替代方案或其他建议,而不是滚动我自己的?

eg

  //示例JSON文档
字符串json ={somewhere:{deep:{inside:123}},anarray:[{ val = 1}]};
JsonElement root = JsonParser.parse(json);

//我想要的是:
JsonElement node = root.getByDOM(somewhere.deep); // {inside:123}
JsonElement node2 = root.getByDOM(somewhere.deep.inside); // 123
JsonElement node3 = root.getByDOM(anarray [0] .val); // 1
// etc


解决方案

与json路径 - 感谢brian的建议。


I'm writing a JSON-style query engine in Java, and it would benefit from the ability to query a JSON document by the DOM path (like you can do in Javascript). I've checked out GSON and Jackson, but neither seem to support this.

Anyone know of any alternatives, or other suggestions rather than rolling my own?

e.g.

//Example JSON document
String json = "{ somewhere : {deep : { inside : 123 } }, anarray : [{val=1}] }";
JsonElement root = JsonParser.parse(json);

//What I'd like:
JsonElement node = root.getByDOM("somewhere.deep");  // {inside : 123}
JsonElement node2 = root.getByDOM("somewhere.deep.inside");  // 123
JsonElement node3 = root.getByDOM("anarray[0].val");  // 1
//etc

解决方案

Gone with json-path - thanks to brian for the suggestion.

这篇关于支持DOM风格访问的Java JSON库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆