如何在体内传递JSON数组 [英] How to pass JSON array inside body in retrofit

查看:117
本文介绍了如何在体内传递JSON数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 {
  "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请求进行改装

I want to pass following request in the body in retrofit.My problem is with json array which is being used as shown above.Can anyone tell how to pass this request in retrofit.Above is the json request which I want to pass in body of retrofit

推荐答案

public class MyPayment {

private String intent;
private MyRedirect redirect_urls;
private MyPayer payer;
private List<MyTrans> transactions;

public MyPayment(String intent, MyRedirect redirect_urls, MyPayer payer, List<MyTrans> transactions) {
    this.intent = intent;
    this.redirect_urls = redirect_urls;
    this.payer = payer;
    this.transactions = transactions;
}

}

公共类MyRedirect {

public class MyRedirect {

private String return_url;
private String cancel_url;

public MyRedirect(String return_url, String cancel_url) {
    this.return_url = return_url;
    this.cancel_url = cancel_url;
}

}

公共类MyPayer { 私人字串payment_method;

public class MyPayer { private String payment_method;

public MyPayer(String payment_method) {
    this.payment_method = payment_method;
}

}

公共类MyTrans { 私人MyAmount金额;

public class MyTrans { private MyAmount amount;

public MyTrans(MyAmount amount) {
    this.amount = amount;
}

}

公共类MyAmount {

public class MyAmount {

private String total;
private String currency;

public MyAmount(String total, String currency) {
    this.total = total;
    this.currency = currency;
}

}

    MyRedirect redi = new MyRedirect("http://example.com/your_redirect_url.html","http://example.com/your_cancel_url.html");
    MyPayer mypay = new MyPayer("paypal");
    List<MyTrans> transs = new ArrayList<MyTrans>();


    MyAmount myamo = new MyAmount("6.70","USD");
    MyTrans transact = new MyTrans(myamo);
    transs.add(transact);
    MyPayment mypayment = new MyPayment("sale",redi,mypay,transs);

这篇关于如何在体内传递JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆