我正在使用 EasyPost(shipping API) 来获取运费。
我可以对货物进行硬编码,但这对我没有帮助。我需要根据用户选择的内容添加数据。
下面是我的代码。如您所见,我有两批货物目前是硬编码的。我想删除硬编码的货物并在其周围添加一个循环并以这种方式添加货物。我可以通过变量传递包裹类型和权重。
因此,如果用户有 5 个包裹,我想添加 5 个货件。
提前致谢!
List<Dictionary<string, object>> shipments;
shipments = new List<Dictionary<string, object>>() {
new Dictionary<string, object>() {
{"parcel", new Dictionary<string, object>() {{ "predefined_package", "MediumFlatRateBox" }, { "weight", 5 }}}
},
new Dictionary<string, object>() {
{"parcel", new Dictionary<string, object>() {{ "predefined_package", "LargeFlatRateBox" }, { "weight", 15 }}}
}
};
parameters = new Dictionary<string, object>() {
{"to_address", toAddress},
{"from_address", fromAddress},
{"reference", "USPS"},
{"shipments", shipments}
};
Order order = Order.Create(parameters);