使用截击从android向服务器发送Json数据

使用截击从android向服务器发送Json数据,android,json,android-volley,Android,Json,Android Volley,我正在尝试使用Volley http客户端将密钥数组从android发送到服务器。但它不发送数组,而是发送字符串。这是我要发送到服务器的数据 {"id": "1231241234312", "steps":[{"id":"123","title":"start"}, {} ] } 步骤键包含数组,但在服务器端,它作为字符串接收。。这是android代码 final Map<String, String> params = new HashMap<String, Str

我正在尝试使用Volley http客户端将密钥数组从android发送到服务器。但它不发送数组,而是发送字符串。这是我要发送到服务器的数据

    {"id": "1231241234312",
"steps":[{"id":"123","title":"start"}, {} ] }
步骤键包含数组,但在服务器端,它作为字符串接收。。这是android代码

final Map<String, String> params = new HashMap<String, String>();
                        JSONObject data = new JSONObject();
                        try {
                            data.put("id", item.getId());
                            data.put("status", 3);
                            data.put("_action", 1);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        params.put("id", task.getId());
                        params.put("steps", data.toString());
final Map params=new HashMap();
JSONObject数据=新的JSONObject();
试一试{
data.put(“id”,item.getId());
数据输入(“状态”,3);
数据。放置(“_action”,1);
}捕获(JSONException e){
e、 printStackTrace();
}
参数put(“id”,task.getId());
参数put(“steps”,data.toString());
private void makeJsonObjReq(){
showProgressDialog();
Map postParam=新的HashMap();
后参数卖出价(“键1”、“值1”);
后参数put(“键2”、“值2”);
JsonObjectRequest JSONObjectReq=新的JsonObjectRequest(Method.POST,
Const.URL\u登录,新JsonObject(postParam),
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
Log.d(TAG,response.toString());
msgressponse.setText(response.toString());
hideProgressDialog();
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
d(标记“Error:+Error.getMessage());
hideProgressDialog();
}
}) {
/**
*传递一些请求头
* */
@凌驾
公共映射getHeaders()引发AuthFailureError{
HashMap headers=新的HashMap();
headers.put(“内容类型”、“应用程序/json;字符集=utf-8”);
返回标题;
}
};
AppController.getInstance().addToRequestQueue(jsonObjReq,tag_json_obj);
}

很抱歉,我无法清楚地告诉您,您是否要求将整个json对象作为字符串发送。但现在您正在发送key_Value parameters()。我正在使用volley将数据从android发送到服务器,并使用volley接受Map类型的参数,这就是为什么我使用这个。我想用分步而不是字符串发送数组。明白我的意思了吗@毗瑟奴·普拉布沃利不仅接受地图上的参数。它还接受字符串中的body。有关实现,请参阅JsonRequest源代码。您可以在字符串中设置正文并重写方法getBody(),从字符串返回字节。是的,但我需要服务器上的关联数组。问题是在有两个键id和步骤的关联数组中,我想针对步骤键发送另一个数组。它是否接受数据作为JsonObject。我们必须把字符串作为一个值
private void makeJsonObjReq() {

            showProgressDialog();

            Map<String, String> postParam= new HashMap<String, String>();
            postParam.put("key1", "Value1");
            postParam.put("key2", "Value2");


    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
            Const.URL_LOGIN, new JsonObject(postParam),
            new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    Log.d(TAG, response.toString());
                    msgResponse.setText(response.toString());
                    hideProgressDialog();
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    hideProgressDialog();
                }
            }) {

        /**
         * Passing some request headers
         * */
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/json; charset=utf-8");
            return headers;
        }



    };

    AppController.getInstance().addToRequestQueue(jsonObjReq,tag_json_obj);

}