获取Json Post请求的回复

时间:2015-04-18 23:34:02

标签: java android json android-volley

我发送带有两个参数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 /错误:com.android.volley.ParseError:org.json.JSONException:字符0的输入结束

1 个答案:

答案 0 :(得分:0)

首先,为什么不在那个按钮上尝试排球请求。然后你可以处理onResponse。希望有帮助吗?