我试图发送一个嵌套的JSONObject到使用JSONObjectRequest的服务器。服务器的形式期待一个JSONObject:发送无跳转字符的嵌套JSON对象
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<String, String> paramsForJSON = new HashMap<String, String>();
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,...)
:
{
"commit":"Sign In",
"user":{
"login":"my username",
"password":"mypassword"
}
}
,但目前我的计划是通过以下(jsonObject.tostring()
)
{
"commit":"Sign In",
"user":" {
\"login\”:\”myusername\”,
\”password\”:\”mypassword\”
} ”
}
的一个JSONObjects发送被由我怎样才能发送上述形式的JSONObject?
你正在使用哪台服务器?像.net或PHP? –
它使用轨道上的红宝石 –
@BabulPatel服务器的相关性是什么? – weston