這給我錯誤,因爲它只期望JSON對象作爲參數。有沒有辦法在POST請求中傳遞字符串?我需要傳遞一個加密的字符串。如何通過volley jsonObjectRequest post mehod傳遞一個字符串?
public JsonObjectRequest addContact(String url, final String contactString, final AddContactCallback addContactCallback) {
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, contactString, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
if (response.length() > 0 && response.getString("status").equalsIgnoreCase("1")) {
if (response.getString("message").equalsIgnoreCase("success")) {// registration
addContactCallback.onAddContactRequestSuccess(....);
}
}else {
addContactCallback.onAddContactRequestError(new VolleyError());
}
} catch (JSONException e) {
e.printStackTrace();
addContactCallback.onAddContactRequestError(new VolleyError());
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (error instanceof NetworkError || error instanceof NoConnectionError) {
addContactCallback.onNetworkError();
} else {
addContactCallback.onAddContactRequestError(error);
}
}
});
jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(
10000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
return jsonObjectRequest;
}
有你的地方contactJSON的嘗試這種新的JSONObject(contactJSON)? –
ya.it不起作用。 – ben10