我有2个类Order.java和OrderedItems.java,如下所示:
public class Order {
private boolean IsScheduled;
private List<OrderedItems> OrderedItems;
public boolean isScheduled() {
return IsScheduled;
}
public void setScheduled(boolean scheduled) {
IsScheduled = scheduled;
}
public List<OrderedItems> getOrderedItems() {
return OrderedItems;
}
public void setOrderedItems(List<OrderedItems> orderedItems) {
OrderedItems = orderedItems;
}
}
public class OrderedItems {
private int ItemId;
private int Quantity;
public OrderedItems(int itemId, int quantity) {
ItemId = itemId;
Quantity = quantity;
}
public int getItemId() {
return ItemId;
}
public void setItemId(int itemId) {
ItemId = itemId;
}
public int getQuantity() {
return Quantity;
}
public void setQuantity(int quantity) {
Quantity = quantity;
}
}
我想使用Android Volley StringRequest以适当的格式将以下对象发布到我的端点:
params.put("IsScheduled", "False");
params.put("OrderedItems[0].ItemId","1" );
params.put("OrderedItems[0].Quantity", "6");
params.put("OrderedItems[1].ItemId", "2");
params.put("OrderedItems[1].Quantity", "5");
params.put("OrderedItems[2].ItemId", "3");
params.put("OrderedItems[2].Quantity", "2");
Log.d(TAG, "getParams: " + order.toString());
params.put("OrderDTO",order.toString());
return params;
}
这是我的WEB API端点:
[HttpPost]
public IHttpActionResult PlaceOrder(OrderDTO dto)
{...}
而OrderDTO是:
public class OrderDTO
{
public bool IsScheduled { get; set; }
public List<OrderedItemsDTO> OrderedItems{ get; set; }
}
我想发送一个Order对象,而不是使用OrderedItems [0]或OrderedItems [1 ...]。 我可以实现吗?