相关疑难解决方法(0)

Volley使用POST方法将JSONObject发送到服务器

我想通过使用volley库{"user_id":12,"answers":{"11":3,"12":4,"13":5}}将以下格式的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();
            }
Run Code Online (Sandbox Code Playgroud)

如果我想使用StringRequest,我应该如何使用POST方法将此JsonObject发送到服务器

post android-volley jsonobject

4
推荐指数
1
解决办法
7817
查看次数

标签 统计

android-volley ×1

jsonobject ×1

post ×1