java - How to add an object as a property of a JsonObject object? -


here doing:

jsonobject jobj = new jsonobject(); jobj.addproperty("name", "great car"); 

i hoping add property value object follows:

jobj.addproperty("car", a_car_object); 

but appears gson not allow me jobj.addproperty("car", a_car_object). going following:

string json = new gson().tojson(jobj); 

to json string.

is doable? using gson right way? or should use hashmap throw data , new gson().tojson()?

you way:

jobj.add("car", new gson().tojsontree(a_car_object)); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -