这是我的json,我需要发布所有这些
{
"name": "name",
"type": "cash",
"PaymentStatus": true
"CartItems": [
{
"ProductId": 1,
"ProductName": "sample string 2",
"Quantity": 3,
"UnitPrice": 4.1,
"Price": 5.1
},{
"ProductId": 1,
"ProductName": "sample string 2",
"Quantity": 3,
"UnitPrice": 4.1,
"Price": 5.1
}
]
}
这是我的Retrofit接口ApiService
@Multipart
@POST("Addtocart")
Call<AddtoCartRes> createOrder(@Body Order order,
@HeaderMap HashMap<String,String> headerMap,
@Path("name") String ShopUserName,
@Path("type") String ShopName,
@Path("PaymentStatus") String SalesLogin
);
这是我的Order类 @SerializedName(“ CartItems”) 列出orderDetailList;
public List<Cart> getOrderDetailList() {
return orderDetailList;
}
public void setOrderDetailList(List<Cart> orderDetailList) {
this.orderDetailList = orderDetailList;
}
答案 0 :(得分:0)
您的请求模型类应该是这样
public class CartItem {
private int ProductId;
private String ProductName;
private int Quantity;
private int UnitPrice;
private int Price;
public void setProductId(int productId) {
ProductId = productId;
}
public void setProductName(String productName) {
ProductName = productName;
}
public void setQuantity(int quantity) {
Quantity = quantity;
}
public void setUnitPrice(int unitPrice) {
UnitPrice = unitPrice;
}
public void setPrice(int price) {
Price = price;
}
}
这是请求模型类
public class MyRequestModel {
private String name;
private String type;
private int PaymentStatus;
private List<CartItem > CartItems;
public void setName(String name) {
this.name = name;
}
public void setType(String type) {
this.type = type;
}
public void setPaymentStatus(int paymentStatus) {
PaymentStatus = paymentStatus;
}
public void setCartItems(List<CartItem> cartItems) {
CartItems = cartItems;
}
}
您的Api看起来像这样
@POST("Addtocart")
Call<AddtoCartRes> createOrder(@HeaderMap HashMap<String,String> headerMap,
@Body MyRequestModel order);