我正在开发应用程序,我使用齐射将数据发送到服务器现在我想将数据发送到json数组中的服务器但不知道如何发送数组?
Map<String, String> postParam = new HashMap<String, String>();
postParam.put("Token", "U2FsdGVkX13CFEM=");
postParam.put("AppDB", "day");
postParam.put("ContentTypeName", "Users");
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
AppConfig.URL_REGISTER_WITHOUT_IMG, 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;
}
};
jsonObjReq.setTag(TAG);
// Adding request to request queue
Volley.newRequestQueue(this).add(jsonObjReq);
}
现在我想发送数据预期的json {“AppDb”:“day”,“ContentTypeName”:“Users”,“Token”:“U2FsdGVkX13CFEM =”,“FilterData”:[{“FilterName”:“EmailId”, “FilterValue”:“通过用户在此处输入电子邮件进行检查”}]
}
试试这个:
JSONArray jsonArray=new JSONArray();
JSONObject jsonObj=new JSONObject();
try {
jsonObj.put("filterName","EmailId");
jsonObj.put("FilterValue",// user email);
} catch (JSONException e) {
e.printStackTrace();
}
jsonArray.put(jsonObj);
将它添加到您的参数中,如下所示:
postParam.put("FilterData",jsonArray);