0
我正在使用volley庫進行請求。我需要發佈參數爲json數組,因爲我在另一端接收它作爲json數組。我怎樣才能將我的參數轉換爲Json數組? 這裏是我的代碼張貼params作爲json在android volley
public void SendData() {{
final StringRequest strReq = new StringRequest(Request.Method.POST, GET_STUDENTS_BY_ID, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.v("failedd",response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Error", "Registration Error: " + error.getMessage());
}
})
{
@Override
protected Map<String, String> getParams() {
// Posting params to register url
Map<String, String> params = new HashMap<String, String>();
params.put("user_id", user_id);
params.put("student_id", studId);
params.put("to", tomail);
params.put("subject", subjects);
params.put("description", descriptions);
return params;
}
@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(strReq, tag_json_obj);
}
請幫助..
? – Nikhil
谷歌的新排球 – Bivin
有語法錯誤..現在請嘗試'新的JSONObject(params)'而不是'新的JsonObject(params)''。 – Nikhil