[英]android Retrofit POST not working - Android Retrofit
这是我的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”)List orderDetailList;
public List<Cart> getOrderDetailList() {
return orderDetailList;
}
public void setOrderDetailList(List<Cart> orderDetailList) {
this.orderDetailList = orderDetailList;
}
您的请求模型类应该像这样
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.