【问题标题】:How do I make JSON file with multiple array如何使用多个数组制作 JSON 文件
【发布时间】:2021-05-08 07:21:44
【问题描述】:

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

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

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

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',
      },
    ]
  };
}

我想为菜肴添加列表。我该怎么做?

【问题讨论】:

    标签: json flutter dart


    【解决方案1】:

    我有这个 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 一样复杂 使用https://javiercbk.github.io 我创建了一个很长的类,所以我不会发布它,但是如果你为它创建一个类,你可以自己尝试一下,你可以添加删除,实际上是所有的东西

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

    【讨论】:

      【解决方案2】:

      我得到了我必须做的事情。

      {
              'index': 3,
              'restaurantName': 'abc',
              'foodCategory': 'abc1',
              'restReview': 1,
              'restImage': 'assets/images/Restaurant.png',
              'distanceFromLocation': 10,
              'restStatus': 'closed',
              'offer': 'Get 5% discount',
              'menuCategories': [
                {
                  'categoryName': 'XYZ',
                  'dishes': [
                    {
                      'dishName': 'XYZ1',
                      'price': 300,
                    },
                    {
                      'dishName': 'XYZ2',
                      'price': 50,
                    },
                    {
                      'dishName': 'XYZ3',
                      'price': 35,
                    },
                    {
                      'dishName': 'XYZ4',
                      'price': 50,
                    },
                  ]
                },
                {
                  'categoryName': 'PQR',
                  'dishes': [
                    {
                      'dishName': 'PQR1',
                      'price': 5,
                    },
                    {
                      'dishName': 'PQR2',
                      'price': 50,
                    },
                    {
                      'dishName': 'PQR3',
                      'price': 35,
                    },
                    {
                      'dishName': 'PQR4',
                      'price': 50,
                    },
                  ]
                },
              ]
            },
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-02-17
        • 2018-11-06
        • 2022-07-06
        • 1970-01-01
        • 2019-08-23
        • 2023-03-22
        • 1970-01-01
        相关资源
        最近更新 更多