Android 将请求作为JSON对象内的JSON参数发送

Android 将请求作为JSON对象内的JSON参数发送,android,json,request,Android,Json,Request,我想以JSON格式发送请求参数。我的问题是我无法发送以下格式的请求。有人能帮我解决吗 { "user": { "email" : "", "password": "", "password_confirmation": "" } } 试试这个 try { JSONObject parent = new JSONObject(); JSONObject jsonObject

我想以JSON格式发送请求参数。我的问题是我无法发送以下格式的请求。有人能帮我解决吗

{
    "user": {
        "email" : "",
        "password": "",
        "password_confirmation": ""
    }
}
试试这个

      try {
            JSONObject parent = new JSONObject();
            JSONObject jsonObject = new JSONObject();

            jsonObject.put("email", "email");
            jsonObject.put("password", "password");
            jsonObject.put("password_confirmation", "password_confirmation");
            parent.put("user", jsonObject);
            Log.d("output", parent.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
它将返回此
JsonObject
输出

{
    "user": {
        "email" : "email",
        "password": "password",
        "password_confirmation": "password_confirmation"
    }
}

你可能在找这样的东西

try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("email", "value");
            jsonObject.put("password", "value");
            jsonObject.put("password_confirmation", "value");

            JSONObject parent = new JSONObject();
            parent.put("user", jsonObject);
        }catch (JSONException e) {
            e.printStackTrace();
        }

创建JsonObject并设置所需的值。如果您尝试了此方法,则只包括JSON db示例。请包括您用于发送上述请求的代码。它非常有用。非常感谢。如果它对您有效,请接受@user3606971的答案。您能帮我发送JSON请求如下:{“gigs_列表_id”:{“2640”:38},“gigs_添加_列表_id”:{“2641”:65,“2642”:66}