我試圖發送一個嵌套的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