Java – accessing nested JSON data in a single get?
•
Java
I tried to get a value from the JSON object How do I get the third level JSON object:
JSON format is as follows:
FeedString = {"level1":[{"level2":{"level3":{"valueIWant":10}}}]}
The code is:
JSONObject jsonFeed = new JSONObject(FeedString); jsonFeed.get("level1.level2.level3.valueIWant");
Can I get the nesting level at once? What should my key look like?
Solution
You can shoot jsonij (JSON in Java); It is the Java version of JSON path, which basically maps part of XPath syntax to JSON objects
In addition, please refer to this so question for other ideas; It looks like JSON - path, has a java version, and uses dot notation
Another option is to build an EL bridge between jsonobjects and things like mvel or ognl, which will provide you with more familiar point symbols (I thought there was an mvel / JSON bridge, but I can't find it now.)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码