Java 我需要用截击库返回结果 >公共void makeJsonObjectRequest(长s、双lat、双lon、int >时区){ >字符串urlJsonObj=”http://projet.dev.e-njaz.com/api/example/getPrayerTimes/“+s+”/”+ >纬度+“/”+lon+“/”+时区; >JsonObjectRequest JSONObjectReq=新的JsonObjectRequest(Request.Method.GET, >urlJsonObj,null,新响应。侦听器(){ >@覆盖 >公共void onResponse(JSONObject响应){ >Log.d(TAG,response.toString()); >试一试{ >DateFormat i=新的SimpleDateFormat(“HH:mm”); >DateFormat o=新的简化格式(“KK:mm a”); >setStr_asar(response.toString()); >pruertimes.str_ishaa=o.format(i.parse(response.getString(“6”).toString()); >}catch(JSONException e){ >e.printStackTrace(); >}catch(parsee异常){ >e.printStackTrace(); > } > } > >},新的Response.ErrorListener(){ >@覆盖 >公共无效onErrorResponse(截击错误){ >d(标记“Error:+Error.getMessage()); >Toast.makeText(getApplicationContext(), >错误.getMessage(),Toast.LENGTH_SHORT).show(); > } > }); >AppController.getInstance().addToRequestQueue(JSONOBJEQ); > > }

Java 我需要用截击库返回结果 >公共void makeJsonObjectRequest(长s、双lat、双lon、int >时区){ >字符串urlJsonObj=”http://projet.dev.e-njaz.com/api/example/getPrayerTimes/“+s+”/”+ >纬度+“/”+lon+“/”+时区; >JsonObjectRequest JSONObjectReq=新的JsonObjectRequest(Request.Method.GET, >urlJsonObj,null,新响应。侦听器(){ >@覆盖 >公共void onResponse(JSONObject响应){ >Log.d(TAG,response.toString()); >试一试{ >DateFormat i=新的SimpleDateFormat(“HH:mm”); >DateFormat o=新的简化格式(“KK:mm a”); >setStr_asar(response.toString()); >pruertimes.str_ishaa=o.format(i.parse(response.getString(“6”).toString()); >}catch(JSONException e){ >e.printStackTrace(); >}catch(parsee异常){ >e.printStackTrace(); > } > } > >},新的Response.ErrorListener(){ >@覆盖 >公共无效onErrorResponse(截击错误){ >d(标记“Error:+Error.getMessage()); >Toast.makeText(getApplicationContext(), >错误.getMessage(),Toast.LENGTH_SHORT).show(); > } > }); >AppController.getInstance().addToRequestQueue(JSONOBJEQ); > > },java,android,Java,Android,你好,evrybody,我需要在函数onResponse中返回对象付款人时间,你能帮我吗。当我更改onReponse的return类型时,我有一个错误。您必须使用“回调”从截击中返回值。这是一个相当复杂的方法,所以我建议另一种方法。您只需在活动中创建一个变量,并在onResponse中设置其值,然后在您想要的任何函数中使用该变量(您甚至可以从onResponse中调用该函数) 如果仍要尝试返回值,请选中 如果你不明白,请在评论中留下它 > public void makeJsonObj

你好,evrybody,我需要在函数onResponse中返回对象付款人时间,你能帮我吗。当我更改onReponse的return类型时,我有一个错误。

您必须使用“回调”从截击中返回值。这是一个相当复杂的方法,所以我建议另一种方法。您只需在活动中创建一个变量,并在onResponse中设置其值,然后在您想要的任何函数中使用该变量(您甚至可以从onResponse中调用该函数)

如果仍要尝试返回值,请选中

如果你不明白,请在评论中留下它

>  public  void makeJsonObjectRequest(Long s,Double lat, Double lon, int
> timezone) {
>         String urlJsonObj = "http://projet.dev.e-njaz.com/api/example/getPrayerTimes/" + s + "/" +
> lat + "/" + lon + "/" + timezone;
>         JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
>                 urlJsonObj, null, new Response.Listener<JSONObject>() {
>             @Override
>             public void onResponse(JSONObject response) {
>                 Log.d(TAG, response.toString());
>                 try {
>                     DateFormat i=new SimpleDateFormat("HH:mm");
>                     DateFormat o = new SimpleDateFormat("KK:mm a");
>                     prayertimes.setStr_asarr(response.toString());
>                     prayertimes.str_ishaa=o.format(i.parse(response.getString("6").toString()));
>                 } catch (JSONException e) {
>                     e.printStackTrace();
>                 } catch (ParseException e) {
>                     e.printStackTrace();
>                 }
>             }
> 
>         }, new Response.ErrorListener() {
>             @Override
>             public void onErrorResponse(VolleyError error) {
>                 VolleyLog.d(TAG, "Error: " + error.getMessage());
>                 Toast.makeText(getApplicationContext(),
>                         error.getMessage(), Toast.LENGTH_SHORT).show(); 
>             }
>         });
>         AppController.getInstance().addToRequestQueue(jsonObjReq);
>          
>     }