即使condtion为true,Retrofit2也总是从json字符串返回false

时间:2018-06-12 09:13:43

标签: retrofit2 boolean-operations

我有以下json字符串{ "pinId": "58DBCD6885431CB8F8910875365F94F4", "msisdn": "254725828213", "verified": true, "attemptsRemaining": 0 } I call the json string from android app using retrofit2

  

我在android应用程序中调用json字符串并使用retrofit2解析,我可以获得值od pinId,msisdn和attemptsRemaining它们是但是为了验证我即使条件为真也会出错。这是我的pojoass   `

/**
 * Created by uzer on 5/25/2018.
 */
import android.widget.Toast;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.util.Iterator;

public class OTPAuthentication  {

    @SerializedName("pinId")
    @Expose
    private String pinId;
    @SerializedName("msisdn")
    @Expose
    private String msisdn;
    @SerializedName("verified")
    @Expose
    private Boolean verified;
    @SerializedName("attemptsRemaining")
    @Expose
    private Integer attemptsRemaining;
    @SerializedName("pinError")
    @Expose
    private String pinError;

    public String getPinId() {
        return pinId;
    }

    public void setPinId(String pinId) {
        this.pinId = pinId;
    }

    public String getMsisdn() {
        return msisdn;
    }

    public void setMsisdn(String msisdn) {
        this.msisdn = msisdn;
    }

    public Boolean getVerified() {
        return verified;
    }

    public void setVerified(Boolean verified) {
        this.verified = verified;
    }

    public Integer getAttemptsRemaining() {
        return attemptsRemaining;
    }

    public void setAttemptsRemaining(Integer attemptsRemaining) {
        this.attemptsRemaining = attemptsRemaining;
    }

    public String getPinError() {
        return pinError;
    }

    public void setPinError(String pinError) {
        this.pinError = pinError;
    }
}`

以下是我解析json字符串的方法在retrofit2中,这是我的retrofit2类。

Retrofit retrofit=new Retrofit.Builder().baseUrl(Api.BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
        Api api=retrofit.create(Api.class);
        Call<OTPAuthentication>call=api.OTPaut(phonenumbersubmission.phone_number.getText().toString(),pinview.getValue().toString());
        call.enqueue(new Callback<OTPAuthentication>() {
            @Override
            public void onResponse(Call<OTPAuthentication> call, final Response<OTPAuthentication> response) {



                    pinview.setPinViewEventListener(new Pinview.PinViewEventListener() {
                        @Override
                        public void onDataEntered(Pinview pinview, boolean b) {


Log.d("Boolean", ((response.body().getVerified().toString())));
                            try {

                                if (response.body()!=null &&(response.body().getVerified()==true) ) {

                              //     Toast.makeText(UserLogin.this, valueOf(response.body().getVerified().t, Toast.LENGTH_LONG).show();

                                    Toast.makeText(UserLogin.this, "Login successful", Toast.LENGTH_LONG).show();
                                    Intent intent = new Intent(UserLogin.this, member_home_page.class);
                                    startActivity(intent);




                                } else {
                                    Toast.makeText(UserLogin.this, "Wrong Pin", Toast.LENGTH_LONG).show();


                                }
                            }
                             catch ( Exception ex){
                                 showmessage("Error",ex.toString());

                                }

                        }


                    });

请帮助我知道为什么即使条件在json字符串中为true,我也总是被证实是假的。 提前谢谢

0 个答案:

没有答案
相关问题