Flutter创建JSON并转换为QR-CODE

时间:2018-10-10 03:38:18

标签: json flutter

我的flutter项目想创建一个json并将json转换为qr代码。我认为我在创建Json时出错。

我的问题:

  1. 创建Json的正确方法是什么?
  2. 是否可以将Json转换为qrocde?

控制台的调试打印:

“” {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;
  }

Json检查图片; enter image description here

0 个答案:

没有答案