【问题标题】:Post JSONObject and get JSONArray request Volley发布 JSONObject 并获取 JSONArray 请求 Volley
【发布时间】:2017-02-14 10:16:18
【问题描述】:

我目前正在尝试将 JsonObject 发布到我的 API 并从服务器获取 JsonArray 响应。我该怎么办?如果我尝试,我会收到异常错误

JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url_test,new JSONObject(params),
            new Response.Listener<JSONObject>() {
                @Override

【问题讨论】:

  • 请您告诉哪个Exception被抛出?
  • 发布崩溃日志和完整代码..
  • com.android.volley.ParseError: org.json.JSONException:
  • 我知道出了什么问题。我得到一个 JSONArray 作为响应并像 JsonObject 一样解析它。我的问题是我将如何使用 volley 创建一个发布 JsonObject 并监听 JsonArray 的发布请求。
  • 您只需要发出 json 数组请求,因为您期望数组返回。我相信你发布的数据无关紧要 -- androidhive.info/2014/05/android-working-with-volley-library-1 -- androidhive.info/2014/07/…

标签: android json post android-volley


【解决方案1】:

试试这些..

  url = "http://your Api post";
    StringRequest postRequest = new StringRequest(Request.Method.POST, url, 
        new Response.Listener<String>() 
        {
            @Override
            public void onResponse(String response) {
                // response
                Log.d("Response", response);
            }
        }, 
        new Response.ErrorListener() 
        {
             @Override
             public void onErrorResponse(VolleyError error) {
                 // error
                 Log.d("Error.Response", response);
           }
        }
    ) {  

//You send the key and value to server you enter here   


 @Override
    protected Map<String, String> getParams() 
    {  
            Map<String, String>  params = new HashMap<String, String>();  
            params.put("key", "value");  

            return params;  
    }
};
queue.add(postRequest);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多