java - JSONArray error getting -



java - JSONArray error getting -

i have login system, , nullpointerexception after getting response or in process request generation. login request is:

try { if (json.getstring(key_success) != null) { string res = json.getstring(key_success); if(res == "sucess"){ pdialog.setmessage("loading user space"); pdialog.settitle("getting data"); userfunctions logout = new userfunctions(); logout.logoutuser(getapplicationcontext()); intent upanel = new intent(getapplicationcontext(), main.class); upanel.addflags(intent.flag_activity_clear_top); pdialog.dismiss(); startactivity(upanel); finish(); }else{ pdialog.dismiss(); loginerrormsg.settext("incorrect username/password"); } } }

and login building is:

public jsonarray loginuser(string email, string password, string appkey) { string conc = email + password + appkey; jsonarray json = jsonparser.getjsonfromurl(loginurl + "?login=" + email + "&password=" + password + "&sign=" + conc); homecoming json; }

in jsonparser have code:

public class jsonparser { static inputstream = null; static jsonarray jobj = null; static string json = ""; // constructor public jsonparser() { } public jsonarray getjsonfromurl(string url) { // making http request // defaulthttpclient defaulthttpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(url); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity(); = httpentity.getcontent(); bufferedreader reader = new bufferedreader(new inputstreamreader( is, "iso-8859-1"), 8); stringbuilder sb = new stringbuilder(); string line = null; while ((line = reader.readline()) != null) { sb.append(line + "\n"); } is.close(); json = sb.tostring(); // seek parse string json object jobj = new jsonarray(json); // homecoming json string homecoming jobj; } }

by way json response of type:

{ "status": "success", "message": "", "session_id": "asdasddfcvxgdgfdfv", "user": [{ "company": "company", "last_name": "last_name·", "name": "name", "middle_name": "middle_name", "phone": "+1234567890", "photo": "avatar.png" }] }

after action error of "null values" this:

error converting result java.lang.nullpointerexception: lock == null error parsing info org.json.jsonexception: end of input @ character 0 of

try way,hope help solve problem.

public jsonobject getjsonfromurl(string url) { seek { httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(url); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity(); stringbuilder buffer = new stringbuilder(); bufferedreader reader = new bufferedreader(new inputstreamreader( httpentity.getcontent(), http.utf_8)); string line = null; seek { while ((line = reader.readline()) != null) { buffer.append(line); } } { reader.close(); } jobj = new jsonobject(reader.tostring()); homecoming jobj; } grab (malformedurlexception localmalformedurlexception) { homecoming null; } grab (ioexception localioexception) { homecoming null; }catch (exception e){ homecoming null; } }

java android json arrays jsonobject

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -