Friday, 15 January 2010

java - Gson to HashMap -



java - Gson to HashMap -

is there way convert string containing json hashmap, every key json-key , value value of json-key? json has no nested values. using gson lib.

for example, given json:

{ "id":3, "location":"newyork" }

resulting hashmap:

<"id", "3"> <"location", "newyork">

thanks

use typetoken, per the gson faq:

gson gson = new gson(); type stringstringmap = new typetoken<map<string, string>>(){}.gettype(); map<string,string> map = gson.fromjson(json, stringstringmap);

no casting. no unnecessary object creation.

java android gson

No comments:

Post a Comment