【发布时间】:2017-02-19 02:25:07
【问题描述】:
我正在尝试使用 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<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,...)
如何发送上述表单中的 JSONObject?
【问题讨论】:
-
您使用的是哪台服务器?喜欢 .net 还是 php ?
-
它正在使用 ruby on rails
-
@BabulPatel 服务器的相关性是什么?
-
使用 Gson 从类中创建 Json 字符串。
标签: java android json android-volley