java - Android hashmap converting to JSON in the wrong format -
i've got random issue cannot seem work out. given next code:
hashmap<string, object> params = new hashmap<string, object>(); params.put("method","getproducts"); hashmap<string, string> methodparams = new hashmap<string, string>(); methodparams.put("currency", currency); params.put("params", methodparams); restclient.setbodyvalueforkey("json", new jsonobject(params).tostring());
the next hashmaps converted json , sent php server.
the server should receive info in next format via post
array ( [json] => {"method":"getproducts","params":{"currency":"gbp"}} )
on android devices (not sure determining factor is) right on others beingness sent as
array ( [json] => {"method":"getproducts","params":"{currency=gbp}"} )
as can see sec hash map beingness converted string , not beingness added hashmap
does know causing inconsistency in parsing hashmaps?
thanks
try doing following
hashmap<string, object> params = new hashmap<string, object>(); params.put("method","getproducts"); hashmap<string, string> methodparams = new hashmap<string, string>(); methodparams.put("currency", currency); params.put("params", new jsonobject(methodparams)); restclient.setbodyvalueforkey("json", new jsonobject(params).tostring());
update
// replace params.put("params", new jsonobject(methodparams).tostring()); //with params.put("params", new jsonobject(methodparams));
java android json hashmap
No comments:
Post a Comment