Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 颤振列表不是类型为';Iterable<;动态>';_Json_Flutter - Fatal编程技术网

Json 颤振列表不是类型为';Iterable<;动态>';

Json 颤振列表不是类型为';Iterable<;动态>';,json,flutter,Json,Flutter,我是颤振开发方面的新手。我犯了一个错误 列表不是“Iterable”类型的子类型 到目前为止,我已经做到了 模范班 class Categories { final String title; final Items items; Categories({this.title, this.items}); factory Categories.fromJson(Map<String, dynamic> json) { return new Categories( t

我是颤振开发方面的新手。我犯了一个错误

列表不是“Iterable”类型的子类型

到目前为止,我已经做到了

模范班

class Categories {
final String title;
final Items items;

Categories({this.title, this.items});

 factory Categories.fromJson(Map<String, dynamic> json) {
  return new Categories(
    title: json['title'],
    items: Items.fromJson(json['Items']));
  }
}

class Items {
final String tag;
final String childId;
final String category;
final String isNew;

Items({this.tag, this.childId, this.category, this.isNew});

factory Items.fromJson(Map<String, dynamic> json) {
return new Items(
    tag: json['id'],
    childId: json['child_category_id'],
    category: json['category'],
    isNew: json['new']);
 }}
类别{
最后的字符串标题;
最后项目;
类别({this.title,this.items});
factory Categories.fromJson(映射json){
返回新类别(
标题:json['title'],
items:items.fromJson(json['items']);
}
}
类别项目{
最后的字符串标签;
最后一个字符串childId;
最终字符串类别;
最后的字符串是新的;
项({this.tag、this.childId、this.category、this.isNew});
factory Items.fromJson(映射json){
退回新物品(
标记:json['id'],
childId:json['child\u category\u id'],
类别:json['category'],
isNew:json['new']);
}}
缅因州班内

List<Categories> categories = [];
var loading = false;

 Future<Null> getNavigationItems() async {
setState(() {
  loading = true;
});

final response = await http.get(Uri.encodeFull(APIs.url_getCategory2));
if (response.statusCode == 200) {
  final data = jsonDecode(utf8.decode(response.bodyBytes));

  setState(() {
    for(Map i in data){
      categories.add(Categories.fromJson(i));
    }


    loading = false;
  });
}
List categories=[];
var加载=假;
未来的getNavigationItems()异步{
设置状态(){
加载=真;
});
最终响应=等待http.get(Uri.encodeFull(api.url_getCategory2));
如果(response.statusCode==200){
最终数据=jsonDecode(utf8.decode(response.bodyBytes));
设置状态(){
用于(数据中的地图i){
categories.add(categories.fromJson(i));
}
加载=假;
});
}
}

我试图从2天开始解决这个问题

这是我从服务器端得到的JSON格式

这是在扩展它的第一个节点之后

更新图像

请帮忙,谢谢

这里是JSON响应,您可以检查


您是否尝试使用
var
而不是
Map

for (var i in data) {
          categories.add(Categories.fromJson(i));
        }

首先,您无法使用json[“title”]将键作为title来获取。我已经重写了,让我们看看:

Map<String, dynamic> categoriesJson = data["categories"];

// get all category name with this because you can't get the key name with "title"
List<String> categoriesName = categoriesJson.keys.map((key) {
  return key.toString();
}).toList();

// depend on the key name, rewrite new Map and put the key name and Items to it
for (String categoryName in categoriesName) {
  Map<String, dynamic> category = {
    "title": categoriesName,
    "Items": categoriesJson[categoriesName]["Items"]
  };

  categories.add(Categories.fromJson(category));
}
Map categoriesJson=data[“categories”];
//使用此选项获取所有类别名称,因为无法获取带有“title”的关键字名称
List categoriesName=categoriesJson.keys.map((键){
return key.toString();
}).toList();
//根据密钥名称,重写新映射并将密钥名称和项放入其中
for(categoriesName中的字符串categoryName){
地图类别={
“标题”:分类名称,
“项目”:categoriesJson[categoriesName][“项目”]
};
categories.add(categories.fromJson(category));
}

只要查看修改后的代码,我已经创建了一个基于动态JSON对象的列表

{
    "icons": {
        "homeIcon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/home.png",
        "cusomIcon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/custom.png",
        "looks": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/look-book.png",
        "policyIcon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/privacy-policy.png",
        "interiorIcon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/interior.png",
        "emailIcon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/newsletter.png",
        "aboutusIcon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/about-us.png"
    },
    "categories": {
        "SOFAS": {
            "icon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/sofa.png",
            "Items": [{
                "tag": "parent",
                "child_category_id": "10",
                "category": "SOFA SETS",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "11",
                "category": "Fabric Sofas",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "12",
                "category": "Wooden Sofas",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "298",
                "category": "3 Seater Sofas",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "299",
                "category": "2 Seater Sofas",
                "new": "0",
                "icon": ""
            }, {
                "tag": "child",
                "child_category_id": "666",
                "category": "L Shaped Corner Sofas",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "312",
                "category": "Chesterfield Sofas",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "1079",
                "category": "Recliners",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "120",
                "category": "Futons",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "13",
                "category": "SOFA CUM BED",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "108",
                "category": "Wooden Sofa Cum Beds",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "107",
                "category": "Fabric Sofa Cum Beds",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "13",
                "category": "Sofa Cum Beds",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "",
                "category": "SEATING",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "124",
                "category": "Wingback Chairs",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "36",
                "category": "Lounge Chairs",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "40",
                "category": "Chaise Lounge",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "126",
                "category": "Arm Chair",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "42",
                "category": "Stools",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "116",
                "category": "Divans",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "77",
                "category": "Ottomans",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "118",
                "category": "Loveseats",
                "new": "1"
            }]
        },
        "LIVING": {
            "icon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/living.png",
            "Items": [{
                "tag": "parent",
                "child_category_id": "16",
                "category": "LIVING STORAGE",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "17",
                "category": "TV Units",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "22",
                "category": "Bookshelves",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "20",
                "category": "Display Unit",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "19",
                "category": "Shoe Racks",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "18",
                "category": "Wall Shelves",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "21",
                "category": "Prayer Units",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "23",
                "category": "Magazine Racks",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "24",
                "category": "TABLES",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "25",
                "category": "Coffee Tables",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "134",
                "category": "Coffee Table Sets",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "27",
                "category": "Nest of Tables",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "135",
                "category": "Side & End Tables",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "26",
                "category": "Console Table",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "116",
                "category": "DIVANS",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "116",
                "category": "Divans",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "38",
                "category": "CHAIRS",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "36",
                "category": "Lounge Chairs",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "124",
                "category": "Wing Chairs",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "35",
                "category": "Rocking Chairs",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "126",
                "category": "Arm Chairs",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "130",
                "category": "Metal Chairs",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "37",
                "category": "Kids Chairs",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "42",
                "category": "Stools",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "43",
                "category": "Benches",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "122",
                "category": "Bean Bags",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "5",
                "category": "OUTDOOR",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "98",
                "category": "Garden Furniture",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "96",
                "category": "Balcony Furniture",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "138",
                "category": "Wooden Swings",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "673",
                "category": "OFFICE FURNITURE",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "681",
                "category": "Office Tables",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "674",
                "category": "Office Chairs",
                "new": "0"
            }]
        },
        "BEDROOM": {
            "icon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/bedroom.png",
            "Items": [{
                "tag": "parent",
                "child_category_id": "55",
                "category": "BEDS",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "59",
                "category": "Queen Size Beds",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "61",
                "category": "King Size Beds",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "58",
                "category": "Single Beds",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "149",
                "category": "Hydraulic Storage Beds",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "150",
                "category": "Upholstered Beds",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "13",
                "category": "Sofa cum Beds",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "151",
                "category": "Trundle Beds",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "60",
                "category": "Double Beds",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "62",
                "category": "Poster Beds",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "116",
                "category": "Divan Beds",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "65",
                "category": "BEDROOM STORAGE & ACCESSORIES",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "67",
                "category": "Bedside Table",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "101",
                "category": "Chest of Drawers",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "91",
                "category": "Wardrobes",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "68",
                "category": "Dressing Table",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "154",
                "category": "Trunk & Blanket Boxes",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "66",
                "category": "Breakfast Table",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "18",
                "category": "Wall Shelves",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "178",
                "category": "Room Dividers",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "74",
                "category": "Mattress & Bedding",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "548",
                "category": "Mattresses",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "549",
                "category": "Single Bed Mattress",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "551",
                "category": "Queen Size mattress",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "550",
                "category": "King Size Mattress",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "552",
                "category": "Double Bed Mattress",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "155",
                "category": "KIDS BEDROOM",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "64",
                "category": "Bunk Beds",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "63",
                "category": "Kids Beds",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "156",
                "category": "Cribs",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "31",
                "category": "Kids Study Table",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "37",
                "category": "Kids Chairs",
                "new": "0"
            }]
        },
        "DINING": {
            "icon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/dining.png",
            "Items": [{
                "tag": "parent",
                "child_category_id": "44",
                "category": "DINING ROOM FURNITURE",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "47",
                "category": "6 Seater Dining Sets",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "46",
                "category": "4 Seater Dining Sets",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "49",
                "category": "2 Seater Dining Sets",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "51",
                "category": "Extendable Dining Sets",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "143",
                "category": "Round Dining Sets",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "48",
                "category": "Dining Tables",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "141",
                "category": "8 Seater Dining Sets",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "44",
                "category": "Dining Table Sets",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "383",
                "category": "DINING CHAIRS",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "383",
                "category": "Dining Chairs",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "43",
                "category": "Benches",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "11",
                "category": "KITCHEN FURNITURE",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "54",
                "category": "Cabinets & Sideboards",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "177",
                "category": "Kitchen Cabinets",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "190",
                "category": "Kitchen Trolley",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "517",
                "category": "Kitchen Island",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "540",
                "category": "Crockery Unit",
                "new": "1"
            }, {
                "tag": "parent",
                "child_category_id": "11",
                "category": "BAR FURNITURE",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "53",
                "category": "Bar Cabinets",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "147",
                "category": "Bar Trolleys",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "148",
                "category": "Wine Racks",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "41",
                "category": "Bar Stools & Chairs",
                "new": "0"
            }]
        },
        "STORAGE": {
            "icon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/stores.png",
            "Items": [{
                "tag": "parent",
                "child_category_id": "16",
                "category": "LIVING STORAGE",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "17",
                "category": "TV Units",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "22",
                "category": "Bookshelves",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "20",
                "category": "Display Units",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "19",
                "category": "Shoe Racks",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "18",
                "category": "Wall Shelves",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "21",
                "category": "Prayer Units",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "23",
                "category": "Magazine Racks",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "100",
                "category": "BEDROOM STORAGE",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "101",
                "category": "Chest of Drawers",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "91",
                "category": "Wardrobes",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "67",
                "category": "Bedside Tables",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "154",
                "category": "Trunk & Blanket Boxes",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "66",
                "category": "Breakfast Table",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "68",
                "category": "Dressing Table",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "18",
                "category": "Wall Shelves",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "11",
                "category": "DINING STORAGE",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "54",
                "category": "Cabinets & Sideboards",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "177",
                "category": "Kitchen Cabinets",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "190",
                "category": "Kitchen Trolley",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "517",
                "category": "Kitchen Island",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "540",
                "category": "Crockery Unit",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "144",
                "category": "Hutch Cabinets",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "160",
                "category": "BATHROOM STORAGE",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "112",
                "category": "Bathroom Cabinets",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "145",
                "category": "BAR FURNITURE",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "53",
                "category": "Bar Cabinets",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "147",
                "category": "Bar Trolleys",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "148",
                "category": "Wine Racks",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "41",
                "category": "Bar Stools & Chairs",
                "new": "0"
            }]
        },
        "STUDY": {
            "icon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/study.png",
            "Items": [{
                "tag": "parent",
                "child_category_id": "24",
                "category": "TABLES",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "29",
                "category": "Study Tables",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "30",
                "category": "Laptop Tables",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "31",
                "category": "Kids Study Tables",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "32",
                "category": "Computer Tables",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "11",
                "category": "CHAIRS",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "37",
                "category": "Kids Study Chairs",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "159",
                "category": "Study Chairs",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "11",
                "category": "STORAGE",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "18",
                "category": "Wall Shelves",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "22",
                "category": "Bookshelves",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "1078",
                "category": "Table Organizer",
                "new": "0"
            }]
        },
        "KIDS FURNITURE": {
            "icon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/kids.png",
            "Items": [{
                "tag": "parent",
                "child_category_id": "155",
                "category": "KIDS BEDROOM",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "63",
                "category": "Kids Beds",
                "new": "1"
            }, {
                "tag": "child",
                "child_category_id": "64",
                "category": "Bunk Beds",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "156",
                "category": "Cribs",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "157",
                "category": "Kids Storage",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "293",
                "category": "KIDS STUDY ROOM",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "37",
                "category": "Kids Chairs",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "31",
                "category": "Kids Study Tables",
                "new": "0"
            }]
        },
        "DECOR": {
            "icon": "https:\/\/www.woodenstreet.com\/images\/mobileapp\/drawericon\/decor.png",
            "Items": [{
                "tag": "parent",
                "child_category_id": "74",
                "category": "LAMPS & LIGHTING",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "573",
                "category": "Table Lamps",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "1084",
                "category": "Floor Lamps",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "558",
                "category": "Study Lamps",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "557",
                "category": "Tripod Lamps",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "71",
                "category": "Hanging Lights",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "176",
                "category": "Home Furnishing",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "176",
                "category": "Rugs And Carpets",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "521",
                "category": "Cushions",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "547",
                "category": "Cushion Covers",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "506",
                "category": "Curtains",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "566",
                "category": "Bed Sheets",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "567",
                "category": "Quilts",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "1094",
                "category": "Runners",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "73",
                "category": "Photo Frames",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "73",
                "category": "Photo Frames",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "1085",
                "category": "Single Photo Frames",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "1086",
                "category": "Multi Photo Frames",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "1087",
                "category": "Collage Photo Frames",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "74",
                "category": "Decor Accessories",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "579",
                "category": "Artificial Flowers",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "411",
                "category": "Artificial Plants",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "594",
                "category": "Miniatures",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "1089",
                "category": "Coasters",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "80",
                "category": "Figurines",
                "new": "0"
            }, {
                "tag": "parent",
                "child_category_id": "74",
                "category": "Wall Art",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "1093",
                "category": "Metal Wall Art",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "580",
                "category": "Wall Frames",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "873",
                "category": "Wooden Jharokha",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "74",
                "category": "Mirror Frames",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "1091",
                "category": "Wall Tiles",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "1092",
                "category": "Wall Clocks",
                "new": "0"
            }, {
                "tag": "child",
                "child_category_id": "1090",
                "category": "Wall Murals",
                "new": "0"
            }]
        }
    }
}
这是我为存储动态数据而创建的模型类

class Categories {
  String itemName;
  List<Item> items;

  Categories({
    this.itemName,
    this.items,
  });
}

class Item {
  String tag;
  String childCategoryId;
  String category;
  String itemNew;

  Item({
    this.tag,
    this.childCategoryId,
    this.category,
    this.itemNew,
  });

  factory Item.fromJson(Map<String, dynamic> json) => Item(
        tag: json["tag"],
        childCategoryId: json["child_category_id"],
        category: json["category"],
        itemNew: json["new"],
      );

  Map<String, dynamic> toJson() => {
        "tag": tag,
        "child_category_id": childCategoryId,
        "category": category,
        "new": itemNew,
      };
}

类别{
字符串itemName;
清单项目;
类别({
这个.itemName,
这个项目,,
});
}
类项目{
字符串标签;
字符串子类别ID;
字符串类别;
字符串项新建;
项目({
这个.tag,
这个,儿童分类,
这一类,,
这是新的,,
});
factory Item.fromJson(映射json)=>Item(
tag:json[“tag”],
childCategoryId:json[“child_category_id”],
类别:json[“类别”],
itemNew:json[“new”],
);
映射到JSON()=>{
“标签”:标签,
“儿童类别id”:儿童类别id,
“类别”:类别,
“新”:项目新,
};
}
这是获取动态数据的主文件

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sample_project_for_api/NewModel.dart';
import 'package:sample_project_for_api/model.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  MyModel yourObject = new MyModel();
  bool _isLoading = false;

  @override
  void initState() {
    super.initState();
    yourMethod();
  }

  yourMethod() async {
    setState(() {
      _isLoading = true;
    });
    String jsonString = await loadFromAssets();

    Map newStringMap = json.decode(jsonString);
    List<Categories> categoryList = new List();
    List<Item> listItem = new List();

    newStringMap['categories'].forEach((key, value) {
      listItem = List<Item>.from(value["Items"].map((x) => Item.fromJson(x)));

      Categories categories = new Categories(itemName: key, items: listItem);
      categoryList.add(categories);
    });

    for (int i = 0; i < categoryList.length; i++) {
      print(
          'This is the item name ############# : ${categoryList[i].itemName}');
      for (int j = 0; j < categoryList[i].items.length; j++) {
        print(
            'This is the item length --------- :${categoryList[i].items[j].category}');
      }
    }

    setState(() {
      _isLoading = false;
    });
  }

  Future<String> loadFromAssets() async {
    return await rootBundle.loadString('json/parse.json');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[Icon(Icons.ac_unit), Icon(Icons.access_alarm)],
      )),
      body: Text('sample text'),
    );
  }
}

导入'dart:convert';
进口“包装:颤振/材料.省道”;
导入“包:flifter/services.dart”;
导入“package:sample_project_for_api/NewModel.dart”;
导入“package:sample_project_for_api/model.dart”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
debugShowCheckedModeBanner:false,
标题:“颤振演示”,
主页:MyHomePage(标题:“颤振演示主页”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
MyModel yourObject=新的MyModel();
bool_isLoading=false;
@凌驾
void initState(){
super.initState();
你的方法();
}
yourMethod()异步{
设置状态(){
_isLoading=true;
});
字符串jsonString=await loadFromAssets();
Map newStringMap=json.decode(jsonString);
List categoryList=新列表();
List listItem=新列表();
newStringMap['categories'].forEach((键,值){
listItem=List.from(值[“Items”].map((x)=>Item.fromJson(x));
Categories Categories=新类别(itemName:key,items:listItem);
类别列表。添加(类别);
});
for(int i=0;i

让我知道它是否有效。

setState((){for(Map i in data){categories.add(categories.fromJson(i));}在这一行,我得到了错误类型错误(类型“\u InternalLinkedHashMap”不是类型“Iterable”的子类型)How??我是这方面的新手。@pskink请检查附加的图像。不起作用。得到相同的错误-发生异常。_TypeError(类型“\u InternalLinkedHashMap”不是类型“Iterable”的子类型)@SanwalSingh好的,然后立即尝试此错误NoSuchMethodError(NoSuchMethodError:方法“[]“”在null上被调用。Receiver:null尝试调用:[](“项”))在“for in”的第一行中添加print(categoryName)并将其显示给meprint(categoryName)给出了此-->cat Name:[SOFAS,