{
"intent":"sale",
"redirect_urls":{
"return_url":"http://example.com/your_redirect_url.html",
"cancel_url":"http://example.com/your_cancel_url.html"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
}
}
]
}
我想在改造中传递以下请求。我的问题是 json 数组,如上所示使用。谁能告诉我如何在改造中传递这个请求。上面是我想传递的 json 请求在改造 body
最佳答案
使用此模型类构建请求主体,您应该根据需要使用 getter 和 setter。
public class PaymentModel {
@SerializedName("intent")
public String intent;
@SerializedName("redirect_urls")
public RedirectUrls redirectUrls;
@SerializedName("payer")
public Payer payer;
@SerializedName("transactions")
public List<Transactions> transactions;
public static class RedirectUrls {
@SerializedName("return_url")
public String returnUrl;
@SerializedName("cancel_url")
public String cancelUrl;
}
public static class Payer {
@SerializedName("payment_method")
public String paymentMethod;
}
public static class Amount {
@SerializedName("total")
public String total;
@SerializedName("currency")
public String currency;
}
public static class Transactions {
@SerializedName("amount")
public Amount amount;
}
}
你还应该添加这个依赖;
compile 'com.google.code.gson:gson:2.8.0'
然后在你的改造请求中;
Call<ResponseBody> PaymentRequest(@Body PaymentModel model);
要查看您构建的完整模型类,请使用;
Gson gson=new Gson();
String modelClass =gson.toJson(model);
关于android - 如何在改造中将 JSON 数组传递到 body 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41543318/