How to post array in retrofit android

前端 未结 7 1796
旧巷少年郎
旧巷少年郎 2020-11-27 19:55

How can I post following parameter in retrofit through post method ?

 \"params\":{\"body\": {
    \"learning_objective_uuids\": [
      \"ED4FE2BB2008FDA9C81         


        
7条回答
  •  佛祖请我去吃肉
    2020-11-27 20:13

    see this example where i need to pass registration fields data as json request

    @POST("magento2apidemo/rest/V1/customers")
    Call customerRegistration(@Body JsonObject registrationData);
    

    here i have created registrationData is

    private static JsonObject generateRegistrationRequest() {
            JSONObject jsonObject = new JSONObject();
            try {
                JSONObject subJsonObject = new JSONObject();
                subJsonObject.put("email", "abc@xyz.com");
                subJsonObject.put("firstname", "abc");
                subJsonObject.put("lastname", "xyz");
    
                jsonObject.put("customer", subJsonObject);
                jsonObject.put("password", "password");
    
            } catch (JSONException e) {
                e.printStackTrace();
            }
            JsonParser jsonParser = new JsonParser();
            JsonObject gsonObject = (JsonObject) jsonParser.parse(jsonObject.toString());
            return gsonObject;
        }
    

提交回复
热议问题