我的flutter项目想创建一个json并将json转换为qr代码。我认为我在创建Json时出错。
我的问题:
控制台的调试打印:
“” {ShopName:饮食通餐厅,ShopAddress:九龙旺角朗豪坊50楼,ShopTel:98765432,OrderDate:10/10/2018,OrderTime:11:29,TableNumber:3,TotalAmount:770,Food:[ {FoodName:西冷牛扒,FoodPrice:180,OrderQuantity:1,FoodCode:3898},{FoodName:云吞鸡,FoodPrice:280,OrderQuantity:2,FoodCode:3898},{FoodName:雪碧,FoodPrice:30, OrderQuantity:1,FoodCode:3898}]}“
我的代码:
var jsson = json.encode(toJson(widget.shop, nowDate, nowTime, widget.tableNumber, widget.foodlist, widget.totalPrice).toString());
debugPrint(jsson);
Map toJson(Shop shop, String nowDate, String nowTime, String tableNumber,
List<Food> foodList, int totalOrderPrice) {
return {
"ShopName": shop.shopName,
"ShopAddress": shop.address,
"ShopTel": shop.tel,
"OrderDate": nowDate.toString(),
"OrderTime": nowTime.toString(),
"TableNumber": tableNumber,
"TotalAmount": totalOrderPrice,
"Food": _jsonFoodList(foodList),
};
}
List<Map> _jsonFoodList(List<Food> foodList) {
List<Map> jsonlist = List();
foodList.forEach((f) {
Map json = {
"FoodName": f.foodName,
"FoodPrice": f.foodPrice,
"OrderQuantity": f.orderQuantity,
"FoodCode": f.foodCode,
};
jsonlist.add(json);
});
return jsonlist;
}