json - Volley Post, doesnt work with parameters. Android Studio -


code getpoststringrequest:

public static stringrequest getpoststringrequest(string url, final string  paramsstring,final response.listener<jsonobject> responselistener){      stringrequest sr = null;      try {         final map<string, string> params = new hashmap();         (string tmp : paramsstring.split("&")) {             params.put(tmp.split("=")[0], tmp.split("=")[1]);         }          log("post", "url: "+url);         log("post", "params: "+paramsstring);          sr = new stringrequest(request.method.post, url,                 new response.listener<string>() {                     @override                     public void onresponse(string response) {                         try{                             jsonobject jo = new jsonobject(response.tostring());                             responselistener.onresponse(jo);                         }catch(jsonexception e){                             log("onresponse", e.getmessage());                         }                     }                 }, new response.errorlistener() {             @override             public void onerrorresponse(volleyerror error) {                 if (error instanceof timeouterror || error instanceof noconnectionerror) {                     log("onerrorresponse", "timeouterror or noconnectionerror");                 } else if (error instanceof authfailureerror) {                     log("onerrorresponse", "authfailureerror");                 } else if (error instanceof servererror) {                     log("onerrorresponse", "servererror");                 } else if (error instanceof networkerror) {                     log("onerrorresponse", "networkerror");                 } else if (error instanceof parseerror) {                     log("onerrorresponse", "parseerror");                 }             }         }){             @override             protected map<string, string> getparams() throws authfailureerror {                 return params;             }         };      }catch (indexoutofboundsexception e){         prototype.reportcrash(e);     }      return sr; } 

code parse:

public appcontroller app(){     return appcontroller.getinstance(); }  public void setmatches(int page){     string url = "http://api.toolboxsv.com/misterpredictor/api/predictions/get/";     string params = "user_id=" + prototype.getuservalue(a, "uid") + "&page="+page+"&status="+getarguments().getstring("status");     stringrequest sr = prototype.getpoststringrequest(url, params, new response.listener<jsonobject>() {         @override         public void onresponse(jsonobject response) {             addmatches(response);         }     });      pgbloading.setvisibility(view.visible);     app().addtorequestqueue(sr); }  void addmatches(jsonobject json){     try {         jsonobject pagination = null;         pagination = json.getjsonobject("pagination");         string total_values = pagination.getstring("total_values");          if(total_values.equals("0")){             matchcard noresultscard = new matchcard("foo", "null");             matchcardlist.add(noresultscard);             adapter.notifydatasetchanged();             pgbloading.setvisibility(view.gone);         }else {             string current_page = pagination.getstring("current_page");             string next_page = pagination.getstring("next_page");              jsonarray predictionsjsonarray = json.getjsonarray("predictions");             (int = 0; < predictionsjsonarray.length(); i++) {                 jsonobject predictionjson = predictionsjsonarray.getjsonobject(i);                 string league = null;                  string league_id = predictionjson.getstring("league_id");                  jsonobject matchjson = predictionjson.getjsonobject("match");                  if (matchjson.has("league")) {                     league = matchjson.getstring("league");                 } else {                     league = "temp";                 }                  string match_id = matchjson.getstring("id");                 string status = matchjson.getstring("status");                 string local = matchjson.getstring("local");                 string visitor = matchjson.getstring("visitor");                 string localshield = matchjson.getstring("local_shield");                 string visitorshield = matchjson.getstring("visitor_shield");                 string date = matchjson.getstring("date");                 string localscore = matchjson.getstring("local_goals");                 string visitorscore = matchjson.getstring("visitor_goals");                  string prediction_status = predictionjson.getstring("prediction_status");                 string prediction_local = predictionjson.getstring("prediction_local");                 string prediction_visitor = predictionjson.getstring("prediction_visitor");                  string localid = matchjson.getstring("dteam1");                 string visitorid = matchjson.getstring("dteam2");                  matchcard match = new matchcard(league, date, local, visitor, localscore,                         visitorscore, localshield, visitorshield,                         prediction_local, prediction_visitor,                         league_id, match_id,                         status, prediction_status, localid, visitorid);                  matchcardlist.add(match);             }              if (next_page.equals("true")) {                 matchcard loadcard = new matchcard(current_page, "true");                 matchcardlist.add(loadcard);             }              adapter.notifydatasetchanged();             pgbloading.setvisibility(view.gone);         }     } catch (jsonexception e) {         prototype.log("asynctask:onpostexecute", "error: " + e.tostring());         string tmp = "org.json.jsonexception: no value for";         pgbloading.setvisibility(view.gone);         if(e.tostring().contains(tmp)){             prototype.toast(a, "no se han encontrado registros.", true);             adapter.notifydatasetchanged();         }else{prototype.reportcrash(e);}     } } 

the problem: api doesnt charge, params please help!!! try fill in recyclerview, code reason doesnt work me , want know or discover solution


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -