【发布时间】:2018-07-07 10:17:01
【问题描述】:
我在解析以下 JSON 对象时遇到问题
"paymentCurrency": "eur",
"paymentOptions": [
{
"paymentOptionId": "1CeGuJt2nkxmaMVf",
"paymentProfileUpdateNeeded": false,
"status": "DISABLED",
"supportedCardTypes": [
"CARD_TYPE_1",
"CARD_TYPE_2",
"CARD_TYPE_3"
],
"type": "TYPE_1"
},
{
"paymentOptionId": "J8iAFXRZZC07rJdG",
"status": "DISABLED",
"type": "TYPE_2"
}
],
"tripCost": "3000",
这是我到目前为止所尝试的。除了 @SerializedName 和 GSON 之外,我不能使用任何东西来解析数组。请在下面找到模型类:
public class MatchDetails {
//other fields
@SerializedName("paymentOptions")
public ArrayList<PaymentOptionWrapper> options;
}
public class PaymentOptionWrapper {
public PaymentOption option;
}
public class PaymentOption {
@SerializedName("paymentOptionId")
public String paymentOptionId;
@SerializedName("paymentProfileUpdateNeeded")
public boolean profileUpdateNeeded;
@SerializedName("status")
public String status;
@SerializedName("supportedCardTypes")
public ArrayList<String> supportedCards;
@SerializedName("type")
public String type;
}
我也试过不使用包装器,直接映射列表但它仍然为空。
【问题讨论】:
-
使用这个jsonschema2pojo.org它可以帮助你
-
用这个工具试过了,生成的代码不起作用。