Reputation: 11
// To parse this JSON data, do
//
// final plans = plansFromJson(jsonString);
import 'dart:convert';
List<Plans> PlansFromJson(String str) => List.from(json.decode(str))
.map((x) => Plans.fromJson(Map.from(x)))
.toList();
// ignore: non_constant_identifier_names
String PlansToJson(List<Plans> data) =>
json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class Plans {
Plans({
required this.id,
required this.title,
required this.details,
required this.selectSubCategory,
});
int id;
String title;
String details;
List<SelectSubCategory> selectSubCategory;
factory Plans.fromJson(Map<String, dynamic> json) => Plans(
id: json["id"],
title: json["title"],
details: json["details"],
selectSubCategory: List<SelectSubCategory>.from(
json["select_sub_category"]
.map((x) => SelectSubCategory.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"id": id,
"title": title,
"details": details,
"select_sub_category":
List<dynamic>.from(selectSubCategory.map((x) => x.toJson())),
};
}
class SelectSubCategory {
SelectSubCategory({
required this.id,
required this.subcategorName,
required this.details,
});
int id;
String subcategorName;
String details;
factory SelectSubCategory.fromJson(Map<String, dynamic> json) =>
SelectSubCategory(
id: json["id"],
subcategorName: json["subcategor_name"],
details: json["details"],
);
Map<String, dynamic> toJson() => {
"id": id,
"subcategor_name": subcategorName,
"details": details,
};
}
List PlansFromJson(String str) => List.from(json.decode(str)) .map((x) => Plans.fromJson(Map.from(x))) .toList(); this line show the error _TypeError (type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable' how to fix this error and why this error repeated my projects lot of times and explain
Upvotes: 0
Views: 154