在改造中将loc阵列与原始体内的其他参数一起传递

时间:2017-01-10 08:09:59

标签: android http-post retrofit retrofit2 android-json

我是新手,在将数据发送到服务器时出现了改进和问题

我试图用我的移动应用程序命中注册api,原始主体如下: -

     {
  "fullName": "test user",
  "gender": "male",
  "age": 25,
  "email": "test@facebook.com",
  "phoneNumber": 7696016749,
  "password": "Admin123#",
  "loc": [30.5234234, 75.4645646545]  ,
  "deviceId": "adssads90ads89afyh89sayfs89afs90afys890afsa",
  "deviceType": "ios"
}

如果我在帖子中点击这个它工作正常,但是代码不在这里我发布了一些我的代码请回顾并让我知道我在哪里做错了。

回应的POJO: -

    public class RequestModel {

    @SerializedName("fullName")
    @Expose
    private String fullName;
    @SerializedName("gender")
    @Expose
    private String gender;
    @SerializedName("age")
    @Expose
    private Integer age;
    @SerializedName("email")
    @Expose
    private String email;
    @SerializedName("phoneNumber")
    @Expose
    private Integer phoneNumber;
    @SerializedName("password")
    @Expose
    private String password;
        @SerializedName("loc")
    @Expose
    private List<Double> loc = null;
    @SerializedName("deviceId")
    @Expose
    private String deviceId;
    @SerializedName("deviceType")
    @Expose
    private String deviceType;

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(Integer phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public List<Double> getLoc() {
        return loc;
    }

    public void setLoc(List<Double> loc) {
        this.loc = loc;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getDeviceType() {
        return deviceType;
    }

    public void setDeviceType(String deviceType) {
        this.deviceType = deviceType;
    }
}

服务类: -

public interface ApiService {

    @POST("/api/registration")
    Call<ResponseModel> registerResponse(@Body RequestModel loginData);
}

我打击api的方法 -

RequestModel contactsModel = new RequestModel();
        contactsModel.setFullName(username);
        contactsModel.setGender(gender);
        contactsModel.setEmail(email);
        contactsModel.setDeviceType("ios");
        contactsModel.setDeviceId("adssads90ads89afyh89sayfs89afs90afys890afsd");
        List<Double> list = new ArrayList<>();
        list.add(30.98877);
        list.add(72.857564);
        contactsModel.setLoc(list);
        apiService = RestClient.getClient().create(ApiService.class);
        Call<ResponseModel> getAllServerContacts = apiService.registerResponse(contactsModel);
        getAllServerContacts.enqueue(new Callback<ResponseModel>() {
            @Override
            public void onResponse(Call<ResponseModel> responseModel, Response<ResponseModel> response) {

                Alerts.dismissLoadingDialog();
                try {
                    if (response.isSuccessful()) {


                        ResponseModel contactsVerified = response.body();
                        SignupModel signupModel = contactsVerified.getSignupModel();
                        String name = signupModel.getFullName();

                    } else {
                        Log.e("nOt", "Successful");
                    }


                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onFailure(Call<ResponseModel> call, Throwable t) {
                Alerts.dismissLoadingDialog();
                Log.e("nOt", "Successful");
            }


        });

位置参数不正确他们以['30 .5234234','75 .4645646545']而不是[30.5234234,75.4645646545]来接收。

如果需要改装,请告诉我如何操作。

由于

0 个答案:

没有答案