json - (Android) JSONObject cannot be converted to JSONArray -
my below android code throwing
org.json.jsonexception: value {"id":1,"displayname":"manish","username":"manish.parab@hotmail.com"} @ authenticateuserresult of type org.json.jsonobject cannot converted jsonarray
code:
string response = common.executehttprequest(url); jsonobject jsonobject = new jsonobject(response); jsonarray jarray = jsonobject.getjsonarray("authenticateuserresult");
response string wcf method.
{"authenticateuserresult":{"displayname":"manish","id":1,"username":"manish.parab@hotmail.com"}}
the exception right, because "authenticateuserresult" value declared element ({}) , not array ({}).
to fix this, use getjsonobject method value of "authenticateuserresult", this:
string response = common.executehttprequest(url); jsonobject jsonobject = new jsonobject(response); jsonobject result = jsonobject.getjsonobject("authenticateuserresult");
after that, can retrieve child element, like:
string musername = result.getstring("username");
Comments
Post a Comment