我尝试使用Volley http客户端从android向服务器发送数组。但是它不是发送数组而是发送字符串。这是我想发送给服务器的数据。
{"id": "1231241234312",
"steps":[{"id":"123","title":"start"}, {} ] }
步骤键包含数组,但在服务器端,它以字符串形式接收.. HEre是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());
答案 0 :(得分:0)
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);
}