json - Gson handling List Item Pairs of type -
json - Gson handling List Item Pairs of type <String, Object> -
i'm reading in json string similar this...
{"flags":{"0":null,"2166136261":null}}
i have no thought on how handle class representation of this? smaller part of complex response i'm slowing trying class out create reading , writing gson simpler.
i can't figure out how represent list item pairs of in class file. seems simple can't figure out @ moment. help appreciated.
use code below
class flag { map<object, object> flags; public map<object, object> getmap() { homecoming flags; } public void setmap(map<object, object> flags) { this.flags = flags; } }
main class
flag flag = new flag(); map<object, object> flags = new hashmap<object, object>(); flags.put("0", "test0"); flags.put("1", "test1"); flag.setmap(flags); system.out.println(new gson().tojson(flag));
output
{"flags":{"1":"test1","0":"test0"}}
this create json string want.
json gson
Comments
Post a Comment