java - GSON does not return JSON key -


i using gson convert objects json. have this:

string name = "myname"; 

and use following statement convert json:

print(new gson().tojson(name)); 

and output : "myname" how can make print in way:

{"name":"myname"} 

there 2 options:

class yourclass {     private string name;      // getters , setters... }  yourclass object = new yourclass(); object.setname("myname"); print(new gson().tojson(object)); 

and using jsonobject:

jsonobject object = new jsonobject(); object.addproperty("name", "myname"); print(new gson().tojson(object); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -