我想使用改造请求传递对象数组。通过Volley,我们将请求数组传递为,
{OrderId=11692, ItemsList[1][Amount]=1, ItemsList[1][id]=29, ItemsList[1][Notes]=2.0, ItemsList[0][TypeId]=23, ItemsList[0][Notes]=15.0, ItemsList[1][serviceId]=28, ItemsList[0][serviceId]=27, ItemsList[0][Amount]=3, ItemsList[0][id]=29, ItemsList[1][TypeId]=23}
如何使用这种格式发送请求?
我正在尝试这样:
@FormUrlEncoded
@POST("api/shidhin/UpdateOrder")
Call<CommonResponse> updateOrderItems(@Header("Authorization") String token, @Field("OrderId") int orderid, @Field("ItemsList[]") ItemsList[] itemsList);
ItemsList.java类文件
public class ItemsList {
@SerializedName("id")
private int id;
@SerializedName("Amount")
private int Amount;
@SerializedName("Notes")
private String Notes;
@SerializedName("serviceId")
private int serviceId;
@SerializedName("TypeId")
private int TypeId;
}
答案 0 :(得分:1)
我通过将对象数组传递为@FieldMap
解决了这个问题。她是O解决这个问题的方式,
创建对象数组,
Order.Orderitems orderitems;
Map<String, String> parms = new HashMap<String, String>();
for (int i = 0; i < orderItems.size(); i++) {
orderitems = orderItems.get(i);
parms.put("ItemsList[" + i + "][id]", String.valueOf(orderitems.getId()));
parms.put("ItemsList[" + i + "][Amount]", String.valueOf(orderitems.getAmount()));
parms.put("ItemsList[" + i + "][Notes]", "");
parms.put("ItemsList[" + i + "][serviceId]", String.valueOf(orderitems.getServiceId()));
parms.put("ItemsList[" + i + "][TypeId]", String.valueOf(orderitems.getServiceTypeId()));
}
还使API调用类似
@FormUrlEncoded
@POST("api/shidhin/UpdateOrder")
Call<CommonResponse> updateOrderItems(@Header("Authorization") String token, @Field("OrderId") int orderid, @FieldMap Map<String, String> parms);