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
Post a Comment