简体   繁体   中英

construct a json in javax.json with list of values for a key

I need to construct a javax.json.JsonObject with following data,

{
 "name": "John",
 "age": 20,
 "interests": [ "Reading", "Mountain Biking", "Hacking" ]
}

Code for the same ?

 JsonObject personObject = Json.createObjectBuilder()
                .add("name", "John")
                .add("age", 20)                
                .add("interests", 
                     Json.createArrayBuilder().add("Reading")
                                              .add("Mountain Biking")
                                              .add("Hacking")
                                              .build()
                    )
                .build();

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