java - error in parsing json object in android -


this question has answer here:

i see code on internet , follow there steps bulif .php files phpmyadmin database test php files success in connection throw web browser, results of web browser php test show {"results_data":"success"}.

public class signupactivity extends asynctask<string, void, string> {      private context context;      public signupactivity(context context) {         this.context = context;     }      protected void onpreexecute() {      }      @override     protected string doinbackground(string... arg0) {         string fullname = arg0[0];         string username = arg0[1];         string password = arg0[2];         string phonenumber = arg0[3];         string emailaddress = arg0[4];          string link;         string data;         bufferedreader bufferedreader;         string result;          try {             data = "?fullname=" + urlencoder.encode(fullname, "utf-8");             data += "&username=" + urlencoder.encode(username, "utf-8");             data += "&password=" + urlencoder.encode(password, "utf-8");             data += "&phonenumber=" + urlencoder.encode(phonenumber, "utf-8");             data += "&emailaddress=" + urlencoder.encode(emailaddress, "utf-8");              link = "http://testandroid.netai.net/signup.php" + data;             url url = new url(link);             httpurlconnection con = (httpurlconnection) url.openconnection();              bufferedreader = new bufferedreader(new inputstreamreader(con.getinputstream()));             result = bufferedreader.readline();             return result;         } catch (exception e) {             return new string("exception: " + e.getmessage());         }     }      @override     protected void onpostexecute(string result) {         string jsonstr = result;         if (jsonstr != null) {             try {                 jsonobject jsonobj = new jsonobject(jsonstr);                 string query_result = jsonobj.getstring("query_result");                 if (query_result.equals("success")) {                     toast.maketext(context, "data inserted successfully. signup successfull.", toast.length_short).show();                 } else if (query_result.equals("failure")) {                     toast.maketext(context, "data not inserted. signup failed.", toast.length_short).show();                 } else {                     toast.maketext(context, "couldn't connect public class signupactivity extends asynctask<string, void, string> {      private context context;      public signupactivity(context context) {         this.context = context;     }      protected void onpreexecute() {      }      @override     protected string doinbackground(string... arg0) {         string fullname = arg0[0];         string username = arg0[1];         string password = arg0[2];         string phonenumber = arg0[3];         string emailaddress = arg0[4];          string link;         string data;         bufferedreader bufferedreader;         string result;          try {             data = "?fullname=" + urlencoder.encode(fullname, "utf-8");             data += "&username=" + urlencoder.encode(username, "utf-8");             data += "&password=" + urlencoder.encode(password, "utf-8");             data += "&phonenumber=" + urlencoder.encode(phonenumber, "utf-8");             data += "&emailaddress=" + urlencoder.encode(emailaddress, "utf-8");              link = "http://testandroid.netai.net/signup.php" + data;             url url = new url(link);             httpurlconnection con = (httpurlconnection) url.openconnection();              bufferedreader = new bufferedreader(new inputstreamreader(con.getinputstream()));             result = bufferedreader.readline();             return result;         } catch (exception e) {             return new string("exception: " + e.getmessage());         }     }      @override     protected void onpostexecute(string result) {         string jsonstr = result;         if (jsonstr != null) {             try {                 jsonobject jsonobj = new jsonobject(jsonstr);                 string query_result = jsonobj.getstring("query_result");                 if (query_result.equals("success")) {                     toast.maketext(context, "data inserted successfully. signup successfull.", toast.length_short).show();                 } else if (query_result.equals("failure")) {                     toast.maketext(context, "data not inserted. signup failed.", toast.length_short).show();                 } else {                     toast.maketext(context, "couldn't connect remote database.", toast.length_short).show();                 }             } catch (jsonexception e) {                 e.printstacktrace();                 toast.maketext(context, "error parsing json data.", toast.length_short).show();             }         } else {             toast.maketext(context, "couldn't json data.", toast.length_short).show();         }     } } 

try first

            jsonobject jsonobj = new jsonobject(jsonstr);             string query_result = jsonobj.getstring("query_result");             if (query_result.equals("success")) {                 toast.maketext(context, "data inserted successfully. signup successfull.", toast.length_short).show();             } else if (query_result.equals("failure")) {                 toast.maketext(context, "data not inserted. signup failed.", toast.length_short).show();             } 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -