[英]Get response from Json Post request
我正在發送帶有兩個參數ID和字符串的POST請求。
public void sendParams(String id,String stringSave, final VolleyCallback vc) {
final String URL = "http://maps.b1.finki.ukim.mk/MapController/save";
HashMap<String, String> params = new HashMap<String, String>();
params.put("cId", id);
params.put("positions", stringSave);
RequestQueue rq=Volley.newRequestQueue(GridTilesActivity.this);
JsonRequest jr=new JsonRequest(Request.Method.POST,URL,params,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
vc.onSuccess(response);
Log.d("Response ",response.toString());
System.out.println(response);
String string=response.optString("positions");
Log.d("Positions",string);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
});
rq.add(jr);
}
現在在按鈕上單擊我想從此POST響應。
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendParams(mapId,pom,new VolleyCallback() {
@Override`enter code here`
public void onSuccess(JSONObject result) {
Log.d("Result","" + result.toString());
}
});
但是我什么也沒得到。這段代碼怎么了..?
我在ErrorResponse上添加了Log.d(“ Error”,volleyError.toString())並得到以下信息:
04-19 23:52:00.375 12825-12825 / com.example.bukic.mapyourroom D / Error:com.android.volley.ParseError:org.json.JSONException:輸入的第0個字符的結尾
首先,為什么不嘗試在該按鈕單擊上執行Volley Request。 然后,您可以處理onResponse。 希望有幫助嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.