我希望使用volley库向服务器发送以下格式的jsonobject:
{
"user_id": 12,
"answers": {
"11": 3,
"12": 4,
"13": 5
}
}
请注意,不要修改或删除任何HTML标记。
如果我想使用 StringRequest,我该如何使用 POST 方法将此 JsonObject 发送到服务器?
JSONObject object = new JSONObject();
try {
object.put("user_id", user_id);
JSONObject answers = new JSONObject();
for (int i = 0; i < questions.size(); i++) {
JSONObject answer = new JSONObject();
answer.put(questions.get(i).getId(),questions.get(i).getAnswer());
answers.put("answers", answer);
object.put("answers", answer);
}
} catch (JSONException e) {
e.printStackTrace();
}
如果我想使用 StringRequest,我该如何使用 POST 方法将此 JsonObject 发送到服务器?