类AllTicketDropdown的No-args构造函数$ CouponCode不存在

时间:2016-08-01 06:24:43

标签: android json gson

当我运行此代码时,它无法从数组中解析 CouponCode优惠券 json对象。它给我错误。

我发布我的所有代码如下。

public class AllTicketDropdown{
public String sendingamount = "";
public String cardfees = "";
public String fees = "";
public String subtotal = "";
public String sendingcurrencycode = "";
public String toamounttotal = "";
public String torate = "";
public String tocurrencycode = "";
public CouponCode coupon;

public String getSendingamount() {
    return sendingamount;
}

public void setSendingamount(String sendingamount) {
    this.sendingamount = sendingamount;
}

public String getCardfees() {
    return cardfees;
}

public void setCardfees(String cardfees) {
    this.cardfees = cardfees;
}

public String getFees() {
    return fees;
}

public void setFees(String fees) {
    this.fees = fees;
}

public String getSubtotal() {
    return subtotal;
}

public void setSubtotal(String subtotal) {
    this.subtotal = subtotal;
}

public String getSendingcurrencycode() {
    return sendingcurrencycode;
}

public void setSendingcurrencycode(String sendingcurrencycode) {
    this.sendingcurrencycode = sendingcurrencycode;
}

public String getToamounttotal() {
    return toamounttotal;
}

public void setToamounttotal(String toamounttotal) {
    this.toamounttotal = toamounttotal;
}

public String getTorate() {
    return torate;
}

public void setTorate(String torate) {
    this.torate = torate;
}

public String getTocurrencycode() {
    return tocurrencycode;
}

public void setTocurrencycode(String tocurrencycode) {
    this.tocurrencycode = tocurrencycode;
}

public CouponCode getCoupon() {
    return coupon;
}

public void setCoupon(CouponCode coupon) {
    this.coupon = coupon;
}


public AllTicketDropdown() {

}


/**
 * Class is used for parcing STATUS...
 */
public class CouponCode{

    public String valid = "";
    public String message = "";
    public String coupondiscount = "";

    public String getValid() {
        return valid;
    }

    public void setValid(String valid) {
        this.valid = valid;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getCoupondiscount() {
        return coupondiscount;
    }

    public void setCoupondiscount(String coupondiscount) {
        this.coupondiscount = coupondiscount;
    }

    public CouponCode() {

    }
}
}

我的Josn回复如下...... 对象优惠券无法解析

{

"error":"0",
"message":"",
"data":[
    {
        "sendingamount":"150",
        "cardfees":0,
        "fees":5,
        "coupon":{
            "valid":"0",
            "message":"Invalid promo code"
        },
        "subtotal":"155.00",
        "sendingcurrencycode":"AUD",
        "toamounttotal":"39000.00",
        "torate":"260.000",
        "tocurrencycode":"NGN"
    }
]
}

我解析json如下......

Gson gson = new Gson();
Type type = new TypeToken<List<AllTicketDropdown>>() {}.getType();
List<AllTicketDropdown> allTicketDropdowns = (List<AllTicketDropdown>) gson.fromJson(jsonObject.get("data").toString(), type);

当我运行此代码时,它会给我以下错误。

Caused by: java.lang.RuntimeException: No-args constructor for class pkg.android.gdm.gdmtransfer.model.AllTicketDropdown$CouponCode does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

请帮助解决此问题。

0 个答案:

没有答案