我正在尝试使用
JSONObjectRequest将嵌套的JSONObject发送到服务器.服务器期望以下列形式的JSONObject:
{
"commit":"Sign In",
"user":{
"login":"my username",
"password":"mypassword"
}
}
但目前我的程序通过以下方式发送(jsonObject.tostring())
{
"commit":"Sign In",
"user":" {
\"login\”:\”myusername\”,
\”password\”:\”mypassword\”
} ”
}
JSONObjects由以下人员制作:
final JSONObject loginRequestJSONObject = new JSONObject();
final JSONObject userJSONObject = new JSONObject();
userJSONObject.put("login", "myuser");
userJSONObject.put("password", "mypass");
loginRequestJSONObject.put("user", userJSONObject);
loginRequestJSONObject.put("commit", "Sign In");
Map paramsForJSON = new HashMap();
paramsForJSON.put("user", userJSONObject.toString().replaceAll("\\\\", "");
paramsForJSON.put("commit", "Sign In");
JSONObject objectToSend = new JSONObject(paramsForJSON);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, objectToSend,...)
如何在上面的表单中发送JSONObject?