简体   繁体   中英

JsonNode Get Key from Value Using Jackson

I have an array which has 3 JsonNodes. I managed to print the JsonNode that I want (which is an array)

Key: modelInformation
Value:[{"projectName":"Jum","modelName":"Jum01","modelId":"122"}}

Unfortunaly it looks like it merged the values together. How do I separate the key from the value in the Value section?

For example

Key: projectname
Value: Jum

field.getKey() or field.getValue() dosent work! Key is modelInformation and value is:

[{"projectName":"Jum","modelName":"Jum01","modelId":"122"}}

You should treat the Value of you json object as a new JSONObject , which is already the case. Or more, the value in your case is an array of Json Objects.

So you can use:

JSONObject jsonObj = new JSONObject(field.getValue());

Or if you are not sure if it's an array or an object, please take a look on this link .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM