首页 > 解决方案 > 如何使用多个数组制作 JSON 文件

问题描述

我以前从未使用过 JSON,所以我不熟悉它的语法。

目前我有多个包含不同数据的数组。

我想创建一个 JSON 对象,其中包含多个数组,每个数组都有几条数据。例如,一个名为 HotelList 的对象,包含多个数组,每个数组对应一个不同的 Hotels 名称。看例子:

class Jsons {
  static var hotelListJson = {
    'hotelData': [
      {
        'index': 0,
        'restaurantName': 'Monginis Cake Shop',
        'foodCategory': 'The Cake Shop',
        'restReview': 5,
        'restImage': 'assets/images/Restaurant1.png',
        'distanceFromLocation': 40,
        'restStatus': 'open',
        'menuCategories': [
          {
            'categoryName': 'Pastry',
            'dishes': [
              'Dutch Pastry',
              'Truffle Pastry',
              'Pipeapple Veg Pastry',
              'Brownee Sqare Veg Pastry',
              'Choco Lava Veg Cup'
            ],
          },
          {
            'categoryName': 'small cake ( half kg)',
            'dishes': [
              'Sapphire Veg Small',
              'Deviles Delite Veg Small',
              'Duth Chocolate Heart Veg (Small)',
              'Shimmer Choco Veg Small'
            ]
          },
          {
            'categoryName': 'Breads',
            'dishes': ['Sandwich Bread', 'Multigrain Bread', 'Brown Bread']
          },
          {
            'categoryName': 'Large cake',
            'dishes': ['Alpine Choco Veg(Large)']
          },
          {
            'categoryName': 'Cookies',
            'dishes': [
              'Almond Cocos Cookies',
              'Shewsburry Cookies',
              'Honey Crunch Cookis',
              'Kesar Cookies',
              'Jeeraa Cookies'
            ]
          },
          {
            'categoryName': 'Savouries',
            'dishes': [
              'Panner pattice',
              'Veg Burger',
              'Pan Pizza Veg',
              'Veg pattice'
            ]
          },
          {
            'categoryName': 'Chocolate',
            'dishes': ['Just Temptations']
          },
          {
            'categoryName': 'Plum & Bar cake',
            'dishes': ['Fruit Bar cake']
          },
        ]
      },
      {
        'index': 1,
        'restaurantName': 'Swami Hotel',
        'foodCategory': 'Family Hotel',
        'restReview': 2,
        'restImage': 'assets/images/Restaurant2.png',
        'distanceFromLocation': 40,
        'restStatus': 'open',
        'menuCategories': [
          {
            'categoryName': 'Veg Starter',
            'dishes': [ 'Paneer pahadi kabab','Garlic chana','Masala papad', 'Manchurian']
          },
          {
            'categoryName': 'Tandoori',
            'dishes': ['Chicken Tandoori','Chicken Tangadi Kabab','Chicken Pahadi Kabab','Mutton Kadhai]
          },
          {
            'categoryName': 'INDIAN BREAD',
            'dishes': ['Aalu Paratha','Paneer Paratha','Nan', 'Butter Nan','Tandoori Roti','Chapati']
          },         
        ]
      },
      {
        'index': 2,
        'restaurantName': 'Diva Sagar',
        'foodCategory': 'Family restaurant',
        'restReview': 5,
        'restImage': 'assets/images/Restaurant3.png',
        'distanceFromLocation': 30,
        'restStatus': 'open',
      },
      {
        'index': 3,
        'restaurantName': 'Smart open pick cake shop',
        'foodCategory': 'Cake Shop',
        'restReview': 1,
        'restImage': 'assets/images/Restaurant4.png',
        'distanceFromLocation': 10,
        'restStatus': 'closed',
        'offer': 'Get 5% discount',
      },
    ]
  };
}

我想在菜肴中添加列表。我怎样才能做到这一点 ?

标签: jsonflutterdart

解决方案


我有这个json

{
"data": [
    {
        "id": 0,
        "code": "string",
        "title": "string",
        "description": "string",
        "orderDetails": [
            {
                "productId": 0,
                "product": {
                    "name": "string",
                    "code": "string",
                    "unit": {
                        "name": "string",
                        "id": 0
                    },
                    "brand": {
                        "name": "string",
                        "imagePath": "string",
                        "id": 0
                    },
                    "country": {
                        "name": "string",
                        "id": 0
                    },
                    "images": [
                        {
                            "path": "string",
                            "type": 1,
                            "id": 0
                        }
                    ],
                    "productInfos": [
                        {
                            "qty": 0,
                            "price": 0,
                            "sumSale": 0,
                            "warranty": true,
                            "score": 0
                        }
                    ],
                    "qtyCart": 0,
                    "oldQtyCart": 0,
                    "sumSale": 0,
                    "saleRoles": [
                        {
                            "groupId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
                            "multipleQTY": 0,
                            "saleRoleType": {
                                "value": "string",
                                "id": 1
                            },
                            "id": 0
                        }
                    ],
                    "groupId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
                    "multipleQTY": 0,
                    "saleRuleType": "string",
                    "familtySearchedHighLight": true,
                    "joinSearchedHighLight": true,
                    "id": 0
                },
                "qty": 0,
                "price": 0,
                "oldQty": 0,
                "oldUnitPrice": 0,
                "unitPrice": 0,
                "finalPrice": 0,
                "sumPrice": 0
            }
        ],
        "orderStatusId": 1,
        "orderStatus": {
            "description": "string",
            "id": 1
        },
        "shippings": [
            {
                "shipperName": "string",
                "shipperHtmlData": "string",
                "driverName": "string",
                "driverHtmlData": "string",
                "car": "string",
                "carIdentity": "string",
                "driverPhone": "string",
                "shipperPhone": "string",
                "orderId": 0,
                "totalItems": 0,
                "shippingCost": 0,
                "increasedCost": 0,
                "increasedCostDescription": "string",
                "blNo": "string",
                "departureTime": "2021-05-08T07:34:22.288Z",
                "deliveredTime": "2021-05-08T07:34:22.288Z",
                "originCity": "string",
                "originProvince": "string",
                "originAddress": "string",
                "targetCity": "string",
                "targetProvince": "string",
                "targetAddress": "string",
                "documentAttach": "string",
                "inTownShipping": true,
                "id": 0
            }
        ],
        "profileId": 0,
        "paymentDocAuthority": "string",
        "referenceId": "string",
        "deliveryProvince": "string",
        "deliveryCity": "string",
        "deliveryAddress": "string",
        "createDm": "2021-05-08T07:34:22.288Z",
        "createDs": "string",
        "finalPrice": 0,
        "sumPrice": 0
    }
],
"isSuccess": true,
"statusCode": 200,
"message": "string"}

它和你的json一样复杂添加删除和实际上所有的东西

您的 json 有问题,我无法在该网站上使用它,请查看我的 json 并更正您的 json


推荐阅读