如何解决如何通过woocommerce rest api在json文件中发布line_items?
我已经在flutter应用程序中成功使用了woocommerce的rest api,但是我被困在一个要通过woocommerce rest API在json文件中添加line_items的地方。
List<CartPdt>linecartitems=[];
linecartitems.map((i)=>{
'product_id':int.parse(i.id),'quantity':i.quantity
}).toList();
var lc=json.encode(linecartitems);
var createOrderUrl = await http.post(
'url',body: json.encode({
'billing': {
'first_name': fname,'last_name': lname,'email': email,'address': address,'city': city,'phone': phone
},'line_items':lc,}),headers: {"Content-Type": "application/json"},);
解决方法
您需要将列表模型转换为JSON。我假设您的模型中没有toJson
方法。添加此内容:
Map<String,dynamic> toJson(){
return {
"product_id": this. product_id,"quantity": this. quantity
};
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。