简体   繁体   中英

Treves the JSON object and manipulate the value in java

What im trying to do is

JSON:

{
aKey:{
        aChildKey:""
     },
bKey:""
}

expected:

aKey:{
        aChildKey:"aKey.aChildKey"
     },
bKey:"bKey"
}

Please can some one help me in getting the expected the value

You need to deserialize the JSON into an object, set the values, then serialize it back into JSON. There are a number of libraries you can use for this, like org.json, gson, or Jackson. Those libraries also allow you to modify the value directly. For example, using org.json, you can do something like this:

JSONObject jsonObject = new JSONObject(myJsonString);
jsonObject.getJSONObject("akey").put("aChildKey","aKey.aChildKey");

See How to parse JSON in Java

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