Reputation: 7944
I'm fetching data from the server, getting the issue in parsing, The key is present in response but showing null every time. I checked all keys and everything but still not finding JSON key and showing null object for deal_banner
. I made response class so many timesin order to get correct parsing and checked every individual key but still not getting correct objects.
This is my response
{
"error":"",
"message":"",
"data":{
"adv_banner":[
{
"banner_image":"https://qa-live.lotuselectronics.com/banner_images/571_457/7be5ea3c00e3a735d0b6c2f88f00be73.png",
"banner_url":"https://qa-live.lotuselectronics.com/web/",
"banner_type":"advt_banner",
"product_id":"",
"category_id":"",
"start_date":"2019-06-04 00:00:00",
"end_date":"2019-12-31 00:00:00",
"is_active":"1"
},
{
"banner_image":"https://qa-live.lotuselectronics.com/banner_images/571_457/8b8eea8290beb5f6d91deaaeb06d44a3.png",
"banner_url":"https://qa-live.lotuselectronics.com/web/",
"banner_type":"advt_banner",
"product_id":"",
"category_id":"",
"start_date":"2019-06-04 00:00:00",
"end_date":"2019-12-31 00:00:00",
"is_active":"1"
},
{
"banner_image":"https://qa-live.lotuselectronics.com/banner_images/571_457/56320b19498306cfb6f4efa5af6784da.png",
"banner_url":"https://qa-live.lotuselectronics.com/web/",
"banner_type":"advt_banner",
"product_id":"",
"category_id":"",
"start_date":"2019-05-14 00:00:00",
"end_date":"2019-12-31 00:00:00",
"is_active":"1"
},
{
"banner_image":"https://qa-live.lotuselectronics.com/banner_images/571_457/a5d908bd63d18a6fcd99aaefe8c47814.png",
"banner_url":"https://qa-live.lotuselectronics.com/web/",
"banner_type":"advt_banner",
"product_id":"",
"category_id":"",
"start_date":"2019-05-14 00:00:00",
"end_date":"2019-12-31 00:00:00",
"is_active":"1"
},
{
"banner_image":"https://qa-live.lotuselectronics.com/banner_images/571_457/720af74fe18534d3646725c5eaa4c410.png",
"banner_url":"https://qa-live.lotuselectronics.com/web/",
"banner_type":"advt_banner",
"product_id":"",
"category_id":"",
"start_date":"2019-05-14 00:00:00",
"end_date":"2019-12-31 00:00:00",
"is_active":"1"
}
],
"banner":[
{
"banner_image":"https://qa-live.lotuselectronics.com/banner_images/original/b767d94a9e4d1c19cc41e90fcc27c790.png",
"banner_url":"https://qa-live.lotuselectronics.com/web/",
"banner_type":"banner",
"product_id":"",
"category_id":"",
"start_date":"2019-05-14 00:00:00",
"end_date":"2019-12-31 00:00:00",
"is_active":"1"
},
{
"banner_image":"https://qa-live.lotuselectronics.com/banner_images/original/7a75574c7618dbf87b981d7433376cba.png",
"banner_url":"https://qa-live.lotuselectronics.com/web/",
"banner_type":"banner",
"product_id":"",
"category_id":"",
"start_date":"2019-05-14 00:00:00",
"end_date":"2019-12-31 00:00:00",
"is_active":"1"
},
{
"banner_image":"https://qa-live.lotuselectronics.com/banner_images/original/043c874ec32d9891b3a54f2bfa14f1ff.jpg",
"banner_url":"https://qa-live.lotuselectronics.com/web/",
"banner_type":"banner",
"product_id":"",
"category_id":"",
"start_date":"2019-05-14 00:00:00",
"end_date":"2019-12-31 00:00:00",
"is_active":"1"
}
],
"deal_banner":[
{
"bnr_message":"",
"banner_id":"666",
"banner_image":"https://qa-live.lotuselectronics.com/banner_images/original/cfdf9a8d58a3d1f4236e7f5ca40949fb.jpg",
"banner_url":"",
"banner_type":"deal_banner",
"product_id":"2987",
"category_id":"",
"start_date":"2019-07-30 00:00:00",
"end_date":"2019-12-31 00:00:00",
"is_active":"1",
"product_name":"Saregama Bluetooth Speaker Carvaan Mini 2.0 Gurbani"
}
],
"top_products_list":[
{
"product_id":"2974",
"product_name":"Philips Shaver AT610",
"cat_id":"87",
"mode_of_sale":"2",
"product_sku":"29361",
"product_msrp":"2115",
"product_mrp":"1999",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1545830488AT610_14-D1P-global-001.jpg",
"product_quantity":"6",
"status":"Active",
"product_brand":"8",
"is_new":"5",
"disc":"5",
"out_of_stock":"0"
},
{
"product_id":"2973",
"product_name":"Philips Shaver AT620",
"cat_id":"87",
"mode_of_sale":"2",
"product_sku":"29512",
"product_msrp":"2695",
"product_mrp":"2499",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1545830203AT620_14-D1P-global-001.jpg",
"product_quantity":"6",
"status":"Active",
"product_brand":"8",
"is_new":"5",
"disc":"7",
"out_of_stock":"0"
},
{
"product_id":"2969",
"product_name":"Philips Shaver S5050/06",
"cat_id":"87",
"mode_of_sale":"2",
"product_sku":"34570",
"product_msrp":"4795",
"product_mrp":"4499",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1545829649S5050.jpg",
"product_quantity":"5",
"status":"Active",
"product_brand":"8",
"is_new":"5",
"disc":"6",
"out_of_stock":"0"
},
{
"product_id":"2967",
"product_name":"Philips Shaver SI 1030",
"cat_id":"87",
"mode_of_sale":"2",
"product_sku":"40506",
"product_msrp":"1795",
"product_mrp":"1699",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1545829320S1030_04-DPP-global-001.jpg",
"product_quantity":"31",
"status":"Active",
"product_brand":"8",
"is_new":"5",
"disc":"5",
"out_of_stock":"0"
},
{
"product_id":"2955",
"product_name":"Kent Egg Boiler 16020",
"cat_id":"91",
"mode_of_sale":"1",
"product_sku":"40776",
"product_msrp":"1950",
"product_mrp":"1199",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_154582622216020-kent-original-imaffn6mkqnhhz6w.jpeg",
"product_quantity":"81",
"status":"Active",
"product_brand":"80",
"is_new":"5",
"disc":"39",
"out_of_stock":"0"
},
{
"product_id":"2558",
"product_name":"Samsung LED TV 32 UA32N4300",
"cat_id":"19",
"mode_of_sale":"1",
"product_sku":"40619",
"product_msrp":"30900",
"product_mrp":"27190",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1538994669Samsung_32N4300_(1).jpg",
"product_quantity":"37",
"status":"Active",
"product_brand":"10",
"is_new":"5",
"disc":"12",
"out_of_stock":"0"
},
{
"product_id":"2513",
"product_name":"Redmi Mobile Note 5 Pro ( 4+64) Gold/Rose Gold/Black",
"cat_id":"33",
"mode_of_sale":"1",
"product_sku":"40087",
"product_msrp":"15999",
"product_mrp":"13499",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1538541777Redmi_note_5_pro_Gold_(1).jpg",
"product_quantity":"78",
"status":"Active",
"product_brand":"138",
"is_new":"5",
"disc":"16",
"out_of_stock":"0"
},
{
"product_id":"2528",
"product_name":"Dell Laptop 7570 A569504WIN9 Slr i5-8th/8GB/1TB/128GB/4GB/W10",
"cat_id":"122",
"mode_of_sale":"1",
"product_sku":"39883",
"product_msrp":"81539",
"product_mrp":"74999",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1539260611Dell_7570_(1).jpg",
"product_quantity":"9",
"status":"Active",
"product_brand":"9",
"is_new":"5",
"disc":"8",
"out_of_stock":"0"
},
{
"product_id":"2494",
"product_name":"Samsung FF Refrigerator 253L RT 28 N3022S8 Elegant Inox",
"cat_id":"59",
"mode_of_sale":"1",
"product_sku":"40115",
"product_msrp":"23850",
"product_mrp":"21590",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1533809995RT28N3022S8.jpg",
"product_quantity":"42",
"status":"Active",
"product_brand":"10",
"is_new":"5",
"disc":"9",
"out_of_stock":"0"
},
{
"product_id":"2409",
"product_name":"LG LED TV 32 32LJ573D",
"cat_id":"19",
"mode_of_sale":"1",
"product_sku":"38595",
"product_msrp":"26490",
"product_mrp":"21499",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_151877774732LJ57_A_Desktop_01_New.jpg",
"product_quantity":"63",
"status":"Active",
"product_brand":"11",
"is_new":"5",
"disc":"19",
"out_of_stock":"0"
},
{
"product_id":"2283",
"product_name":"LG SA Washing Machine 6.5 WP7550R3FA Dark Grey",
"cat_id":"67",
"mode_of_sale":"1",
"product_sku":"38323",
"product_msrp":"12400",
"product_mrp":"11499",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_15356952187a.jpg",
"product_quantity":"103",
"status":"Active",
"product_brand":"11",
"is_new":"5",
"disc":"7",
"out_of_stock":"0"
},
{
"product_id":"1756",
"product_name":"Godrej SA Washing Machine 8.0 GWS 800 PDS Lilac Sprinkle",
"cat_id":"67",
"mode_of_sale":"1",
"product_sku":"35418",
"product_msrp":"18200",
"product_mrp":"16299",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1468244714ws_800_pds_lilac_sprinkle_front.jpg",
"product_quantity":"28",
"status":"Active",
"product_brand":"62",
"is_new":"5",
"disc":"10",
"out_of_stock":"0"
},
{
"product_id":"790",
"product_name":"Bajaj Cook Top CGX3 ECO",
"cat_id":"106",
"mode_of_sale":"1",
"product_sku":"34663",
"product_msrp":"6990",
"product_mrp":"3899",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1439036378Bajaj_CGX3.jpg",
"product_quantity":"36",
"status":"Active",
"product_brand":"14",
"is_new":"5",
"disc":"44",
"out_of_stock":"0"
},
{
"product_id":"553",
"product_name":"Jaquar Water Heater ELENA 15L",
"cat_id":"75",
"mode_of_sale":"1",
"product_sku":"33129",
"product_msrp":"8300",
"product_mrp":"7699",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1438945103Jaquar-25-Elena-digital-Geyser-SDL892249340-1-576cc.jpg",
"product_quantity":"32",
"status":"Active",
"product_brand":"78",
"is_new":"5",
"disc":"7",
"out_of_stock":"0"
}
],
"trending":[
{
"product_id":"2521",
"product_name":"Kent Aata & Bread Maker",
"cat_id":"91",
"mode_of_sale":"1",
"product_sku":"38990",
"product_msrp":"10000",
"product_mrp":"8399",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1529651058kent-atta-maker-bread-maker.jpg",
"product_quantity":"7",
"status":"Active",
"product_brand":"80",
"is_new":"6",
"disc":"16",
"out_of_stock":"0"
},
{
"product_id":"2509",
"product_name":"Saregama Carvaan Portable Digital Music Player (Cherry with remote)",
"cat_id":"15",
"mode_of_sale":"1",
"product_sku":"40383",
"product_msrp":"6390",
"product_mrp":"6390",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1539164350Saregama_Cherryred_(1).jpg",
"product_quantity":"34",
"status":"Active",
"product_brand":"140",
"is_new":"6",
"disc":"0",
"out_of_stock":"0"
},
{
"product_id":"2546",
"product_name":"Micromax Split AC 1.5T ACS18C3A3QS2WH (3 Star)",
"cat_id":"64",
"mode_of_sale":"1",
"product_sku":"40630",
"product_msrp":"38990",
"product_mrp":"27999",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1529933844Micromax_Split_AC_ACS18C3A3QS2WH.jpg",
"product_quantity":"53",
"status":"Active",
"product_brand":"18",
"is_new":"6",
"disc":"28",
"out_of_stock":"0"
},
{
"product_id":"2545",
"product_name":"Micromax Split AC 1.5T ACI18C3A3QS2WH (3 Star)",
"cat_id":"64",
"mode_of_sale":"1",
"product_sku":"40628",
"product_msrp":"42990",
"product_mrp":"29999",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1529933763Micromax_Split_AC_ACI18C3A3QS2WH.jpg",
"product_quantity":"67",
"status":"Active",
"product_brand":"18",
"is_new":"6",
"disc":"30",
"out_of_stock":"0"
},
{
"product_id":"2544",
"product_name":"Micromax Split AC 1.0T ACS12C3C4QS3WH (3 Star)",
"cat_id":"64",
"mode_of_sale":"1",
"product_sku":"40632",
"product_msrp":"31990",
"product_mrp":"24999",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1529661214112D5cA4skL.jpg",
"product_quantity":"37",
"status":"Active",
"product_brand":"18",
"is_new":"6",
"disc":"22",
"out_of_stock":"0"
},
{
"product_id":"2540",
"product_name":"Videocon DC Refrigerator 190L VU201E",
"cat_id":"59",
"mode_of_sale":"1",
"product_sku":"40050",
"product_msrp":"12190",
"product_mrp":"10999",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1540286592Videocon_L3_(1).jpg",
"product_quantity":"113",
"status":"Active",
"product_brand":"22",
"is_new":"6",
"disc":"10",
"out_of_stock":"0"
},
{
"product_id":"2535",
"product_name":"Samsung TL Washing Machine 6.0 WA 60M4300HD Imperial Silver",
"cat_id":"66",
"mode_of_sale":"1",
"product_sku":"38523",
"product_msrp":"16400",
"product_mrp":"15800",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1529658721wa62m4100hy-tl-samsung-original-imaewmc9m68rayng.jpeg",
"product_quantity":"62",
"status":"Active",
"product_brand":"10",
"is_new":"6",
"disc":"4",
"out_of_stock":"0"
},
{
"product_id":"2524",
"product_name":"Vise LED TV 32 VD32H701",
"cat_id":"19",
"mode_of_sale":"1",
"product_sku":"38890",
"product_msrp":"18000",
"product_mrp":"10999",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1529652940be0295fe-f1e4-48d9-9314-a047c8a1530d_340x340.png",
"product_quantity":"188",
"status":"Active",
"product_brand":"119",
"is_new":"6",
"disc":"39",
"out_of_stock":"0"
},
{
"product_id":"2498",
"product_name":"Speakers Echo",
"cat_id":"31",
"mode_of_sale":"1",
"product_sku":"39896",
"product_msrp":"9999",
"product_mrp":"7999",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/1_154583103771dK5nbXP3L._SL1000__.jpg",
"product_quantity":"16",
"status":"Active",
"product_brand":"135",
"is_new":"6",
"disc":"20",
"out_of_stock":"0"
},
{
"product_id":"2249",
"product_name":"Usha Halogen Oven 3514",
"cat_id":"105",
"mode_of_sale":"1",
"product_sku":"37007",
"product_msrp":"11050",
"product_mrp":"5599",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_152965025051l4L6d4U2L.jpg",
"product_quantity":"26",
"status":"Active",
"product_brand":"116",
"is_new":"6",
"disc":"49",
"out_of_stock":"0"
},
{
"product_id":"2052",
"product_name":"Philips Coffee Maker HD 7431/20",
"cat_id":"112",
"mode_of_sale":"1",
"product_sku":"35558",
"product_msrp":"1995",
"product_mrp":"1899",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_147825365735558.jpg",
"product_quantity":"5",
"status":"Active",
"product_brand":"8",
"is_new":"6",
"disc":"5",
"out_of_stock":"0"
},
{
"product_id":"1999",
"product_name":"Vise LED TV 24 VD24H601",
"cat_id":"22",
"mode_of_sale":"1",
"product_sku":"36801",
"product_msrp":"13000",
"product_mrp":"8999",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1475911213-Vise-VD24H601-LED-TVs-HD-Ready.png",
"product_quantity":"100",
"status":"Active",
"product_brand":"119",
"is_new":"6",
"disc":"31",
"out_of_stock":"0"
},
{
"product_id":"1736",
"product_name":"Samsung TL Washing Machine 9.0 WA 90J5710SG Silver",
"cat_id":"69",
"mode_of_sale":"1",
"product_sku":"36600",
"product_msrp":"29500",
"product_mrp":"28400",
"product_image":"https://qa-live.lotuselectronics.com/product_images/200/0_1467115358in_WA90J5710SG-TL_001_Front.jpg",
"product_quantity":"5",
"status":"Active",
"product_brand":"10",
"is_new":"6",
"disc":"4",
"out_of_stock":"0"
}
]
}
}
This is my response class
class Home {
String error;
String message;
Data data;
Home({
this.error,
this.message,
this.data,
});
factory Home.fromMap(Map<String, dynamic> json) => Home(
error: json["error"] == null ? null : json["error"],
message: json["message"] == null ? null : json["message"],
data: json["data"] == null ? null : Data.fromMap(json["data"]),
);
Map<String, dynamic> toMap() => {
"error": error == null ? null : error,
"message": message == null ? null : message,
"data": data == null ? null : data.toMap(),
};
}
class Data {
List<Banners> advBanner;
List<Banners> banner;
List<DealBanner> dealBanner;
List<TopProductsList> topProductsList;
List<TopProductsList> trending;
Data({
this.advBanner,
this.banner,
this.dealBanner,
this.topProductsList,
this.trending,
});
factory Data.fromMap(Map<String, dynamic> json) => Data(
advBanner: json["adv_banner"] == null
? null
: List<Banners>.from(
json["adv_banner"].map((x) => Banners.fromMap(x))),
banner: json["banner"] == null
? null
: List<Banners>.from(json["banner"].map((x) => Banners.fromMap(x))),
dealBanner: json["deal_banner"] == null
? null
: List<DealBanner>.from(
json["deal_banner"].map((x) => DealBanner.fromMap(x))),
topProductsList: json["top_products_list"] == null
? null
: List<TopProductsList>.from(json["top_products_list"]
.map((x) => TopProductsList.fromMap(x))),
trending: json["trending"] == null
? null
: List<TopProductsList>.from(
json["trending"].map((x) => TopProductsList.fromMap(x))),
);
Map<String, dynamic> toMap() => {
"adv_banner": advBanner == null
? null
: List<dynamic>.from(advBanner.map((x) => x.toMap())),
"banner": banner == null
? null
: List<dynamic>.from(banner.map((x) => x.toMap())),
/* "deal_banner": dealBanner == null
? null
: List<dynamic>.from(dealBanner.map((x) => x.toMap())),
"top_products_list": topProductsList == null
? null
: List<dynamic>.from(topProductsList.map((x) => x.toMap())),
"trending": trending == null
? null
: List<dynamic>.from(trending.map((x) => x.toMap())),*/
};
}
class Banners {
String bannerImage;
String bannerUrl;
String bannerType;
int productId;
String categoryId;
DateTime startDate;
DateTime endDate;
String isActive;
Banners({
this.bannerImage,
this.bannerUrl,
this.bannerType,
this.productId,
this.categoryId,
this.startDate,
this.endDate,
this.isActive,
});
factory Banners.fromMap(Map<String, dynamic> json) => Banners(
bannerImage: json["banner_image"] == null ? null : json["banner_image"],
bannerUrl: json["banner_url"] == null ? null : json["banner_url"],
bannerType: json["banner_type"] == null ? null : json["banner_type"],
productId: json["product_id"] == null ? null : json["product_id"],
categoryId: json["category_id"] == null ? null : json["category_id"],
startDate: json["start_date"] == null
? null
: DateTime.parse(json["start_date"]),
endDate:
json["end_date"] == null ? null : DateTime.parse(json["end_date"]),
isActive: json["is_active"] == null ? null : json["is_active"],
);
Map<String, dynamic> toMap() => {
"banner_image": bannerImage == null ? null : bannerImage,
"banner_url": bannerUrl == null ? null : bannerUrl,
"banner_type": bannerType == null ? null : bannerType,
"product_id": productId == null ? null : productId,
"category_id": categoryId == null ? null : categoryId,
"start_date": startDate == null ? null : startDate.toIso8601String(),
"end_date": endDate == null ? null : endDate.toIso8601String(),
"is_active": isActive == null ? null : isActive,
};
}
class DealBanner {
String bnrMessage;
String bannerId;
String bannerImage;
String bannerUrl;
String bannerType;
String productId;
String categoryId;
DateTime startDate;
DateTime endDate;
String isActive;
String productName;
DealBanner({
this.bnrMessage,
this.bannerId,
this.bannerImage,
this.bannerUrl,
this.bannerType,
this.productId,
this.categoryId,
this.startDate,
this.endDate,
this.isActive,
this.productName,
});
factory DealBanner.fromMap(Map<String, dynamic> json) => DealBanner(
bnrMessage: json["bnr_message"] == null ? null : json["bnr_message"],
bannerId: json["banner_id"] == null ? null : json["banner_id"],
bannerImage: json["banner_image"] == null ? null : json["banner_image"],
bannerUrl: json["banner_url"] == null ? null : json["banner_url"],
bannerType: json["banner_type"] == null ? null : json["banner_type"],
productId: json["product_id"] == null ? null : json["product_id"],
categoryId: json["category_id"] == null ? null : json["category_id"],
startDate: json["start_date"] == null
? null
: DateTime.parse(json["start_date"]),
endDate:
json["end_date"] == null ? null : DateTime.parse(json["end_date"]),
isActive: json["is_active"] == null ? null : json["is_active"],
productName: json["product_name"] == null ? null : json["product_name"],
);
Map<String, dynamic> toMap() => {
"bnr_message": bnrMessage == null ? null : bnrMessage,
"banner_id": bannerId == null ? null : bannerId,
"banner_image": bannerImage == null ? null : bannerImage,
"banner_url": bannerUrl == null ? null : bannerUrl,
"banner_type": bannerType == null ? null : bannerType,
"product_id": productId == null ? null : productId,
"category_id": categoryId == null ? null : categoryId,
"start_date": startDate == null ? null : startDate.toIso8601String(),
"end_date": endDate == null ? null : endDate.toIso8601String(),
"is_active": isActive == null ? null : isActive,
"product_name": productName == null ? null : productName,
};
}
class TopProductsList {
String productId;
String productName;
String catId;
String modeOfSale;
String productSku;
String productMsrp;
String productMrp;
String productImage;
String productQuantity;
Status status;
String productBrand;
String isNew;
String disc;
String outOfStock;
TopProductsList({
this.productId,
this.productName,
this.catId,
this.modeOfSale,
this.productSku,
this.productMsrp,
this.productMrp,
this.productImage,
this.productQuantity,
this.status,
this.productBrand,
this.isNew,
this.disc,
this.outOfStock,
});
factory TopProductsList.fromMap(Map<String, dynamic> json) => TopProductsList(
productId: json["product_id"] == null ? null : json["product_id"],
productName: json["product_name"] == null ? null : json["product_name"],
catId: json["cat_id"] == null ? null : json["cat_id"],
modeOfSale: json["mode_of_sale"] == null ? null : json["mode_of_sale"],
productSku: json["product_sku"] == null ? null : json["product_sku"],
productMsrp: json["product_msrp"] == null ? null : json["product_msrp"],
productMrp: json["product_mrp"] == null ? null : json["product_mrp"],
productImage:
json["product_image"] == null ? null : json["product_image"],
productQuantity:
json["product_quantity"] == null ? null : json["product_quantity"],
status:
json["status"] == null ? null : statusValues.map[json["status"]],
productBrand:
json["product_brand"] == null ? null : json["product_brand"],
isNew: json["is_new"] == null ? null : json["is_new"],
disc: json["disc"] == null ? null : json["disc"],
outOfStock: json["out_of_stock"] == null ? null : json["out_of_stock"],
);
Map<String, dynamic> toMap() => {
"product_id": productId == null ? null : productId,
"product_name": productName == null ? null : productName,
"cat_id": catId == null ? null : catId,
"mode_of_sale": modeOfSale == null ? null : modeOfSale,
"product_sku": productSku == null ? null : productSku,
"product_msrp": productMsrp == null ? null : productMsrp,
"product_mrp": productMrp == null ? null : productMrp,
"product_image": productImage == null ? null : productImage,
"product_quantity": productQuantity == null ? null : productQuantity,
"status": status == null ? null : statusValues.reverse[status],
"product_brand": productBrand == null ? null : productBrand,
"is_new": isNew == null ? null : isNew,
"disc": disc == null ? null : disc,
"out_of_stock": outOfStock == null ? null : outOfStock,
};
}
enum Status { ACTIVE }
final statusValues = EnumValues({"Active": Status.ACTIVE});
class EnumValues<T> {
Map<String, T> map;
Map<T, String> reverseMap;
EnumValues(this.map);
Map<T, String> get reverse {
if (reverseMap == null) {
reverseMap = map.map((k, v) => new MapEntry(v, k));
}
return reverseMap;
}
}
calling service like this
Future<Home> homeService() async {
http.Response res = await http.get(WebConstant.HOME);
final jsonData = json.decode(res.body);
debugPrint("Home Data:---" + res.body);
if (res.statusCode == 200) {
try {
var map = Map<String, dynamic>.from(jsonData);
var home = Home.fromMap(map);
return home;
} catch (e) {
debugPrint("Exceptioin:---" + e);
}
} else {
throw Exception('Failed to load post');
}
}
Upvotes: 3
Views: 3043
Reputation: 54367
I paste your json string to https://app.quicktype.io/ and get correct structure
and simulate your json with a text file in web server
I have print deal banner image url to prove it work fine without error
you can parse your json string with this command
final home = homeFromJson(jsonString);
class file
// To parse this JSON data, do
//
// final home = homeFromJson(jsonString);
import 'dart:convert';
Home homeFromJson(String str) => Home.fromJson(json.decode(str));
String homeToJson(Home data) => json.encode(data.toJson());
class Home {
String error;
String message;
Data data;
Home({
this.error,
this.message,
this.data,
});
factory Home.fromJson(Map<String, dynamic> json) => Home(
error: json["error"] == null ? null : json["error"],
message: json["message"] == null ? null : json["message"],
data: json["data"] == null ? null : Data.fromJson(json["data"]),
);
Map<String, dynamic> toJson() => {
"error": error == null ? null : error,
"message": message == null ? null : message,
"data": data == null ? null : data.toJson(),
};
}
class Data {
List<Banner> advBanner;
List<Banner> banner;
List<DealBanner> dealBanner;
List<TopProductsList> topProductsList;
List<TopProductsList> trending;
Data({
this.advBanner,
this.banner,
this.dealBanner,
this.topProductsList,
this.trending,
});
factory Data.fromJson(Map<String, dynamic> json) => Data(
advBanner: json["adv_banner"] == null ? null : List<Banner>.from(json["adv_banner"].map((x) => Banner.fromJson(x))),
banner: json["banner"] == null ? null : List<Banner>.from(json["banner"].map((x) => Banner.fromJson(x))),
dealBanner: json["deal_banner"] == null ? null : List<DealBanner>.from(json["deal_banner"].map((x) => DealBanner.fromJson(x))),
topProductsList: json["top_products_list"] == null ? null : List<TopProductsList>.from(json["top_products_list"].map((x) => TopProductsList.fromJson(x))),
trending: json["trending"] == null ? null : List<TopProductsList>.from(json["trending"].map((x) => TopProductsList.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"adv_banner": advBanner == null ? null : List<dynamic>.from(advBanner.map((x) => x.toJson())),
"banner": banner == null ? null : List<dynamic>.from(banner.map((x) => x.toJson())),
"deal_banner": dealBanner == null ? null : List<dynamic>.from(dealBanner.map((x) => x.toJson())),
"top_products_list": topProductsList == null ? null : List<dynamic>.from(topProductsList.map((x) => x.toJson())),
"trending": trending == null ? null : List<dynamic>.from(trending.map((x) => x.toJson())),
};
}
class Banner {
String bannerImage;
String bannerUrl;
String bannerType;
String productId;
String categoryId;
DateTime startDate;
DateTime endDate;
String isActive;
Banner({
this.bannerImage,
this.bannerUrl,
this.bannerType,
this.productId,
this.categoryId,
this.startDate,
this.endDate,
this.isActive,
});
factory Banner.fromJson(Map<String, dynamic> json) => Banner(
bannerImage: json["banner_image"] == null ? null : json["banner_image"],
bannerUrl: json["banner_url"] == null ? null : json["banner_url"],
bannerType: json["banner_type"] == null ? null : json["banner_type"],
productId: json["product_id"] == null ? null : json["product_id"],
categoryId: json["category_id"] == null ? null : json["category_id"],
startDate: json["start_date"] == null ? null : DateTime.parse(json["start_date"]),
endDate: json["end_date"] == null ? null : DateTime.parse(json["end_date"]),
isActive: json["is_active"] == null ? null : json["is_active"],
);
Map<String, dynamic> toJson() => {
"banner_image": bannerImage == null ? null : bannerImage,
"banner_url": bannerUrl == null ? null : bannerUrl,
"banner_type": bannerType == null ? null : bannerType,
"product_id": productId == null ? null : productId,
"category_id": categoryId == null ? null : categoryId,
"start_date": startDate == null ? null : startDate.toIso8601String(),
"end_date": endDate == null ? null : endDate.toIso8601String(),
"is_active": isActive == null ? null : isActive,
};
}
class DealBanner {
String bnrMessage;
String bannerId;
String bannerImage;
String bannerUrl;
String bannerType;
String productId;
String categoryId;
DateTime startDate;
DateTime endDate;
String isActive;
String productName;
DealBanner({
this.bnrMessage,
this.bannerId,
this.bannerImage,
this.bannerUrl,
this.bannerType,
this.productId,
this.categoryId,
this.startDate,
this.endDate,
this.isActive,
this.productName,
});
factory DealBanner.fromJson(Map<String, dynamic> json) => DealBanner(
bnrMessage: json["bnr_message"] == null ? null : json["bnr_message"],
bannerId: json["banner_id"] == null ? null : json["banner_id"],
bannerImage: json["banner_image"] == null ? null : json["banner_image"],
bannerUrl: json["banner_url"] == null ? null : json["banner_url"],
bannerType: json["banner_type"] == null ? null : json["banner_type"],
productId: json["product_id"] == null ? null : json["product_id"],
categoryId: json["category_id"] == null ? null : json["category_id"],
startDate: json["start_date"] == null ? null : DateTime.parse(json["start_date"]),
endDate: json["end_date"] == null ? null : DateTime.parse(json["end_date"]),
isActive: json["is_active"] == null ? null : json["is_active"],
productName: json["product_name"] == null ? null : json["product_name"],
);
Map<String, dynamic> toJson() => {
"bnr_message": bnrMessage == null ? null : bnrMessage,
"banner_id": bannerId == null ? null : bannerId,
"banner_image": bannerImage == null ? null : bannerImage,
"banner_url": bannerUrl == null ? null : bannerUrl,
"banner_type": bannerType == null ? null : bannerType,
"product_id": productId == null ? null : productId,
"category_id": categoryId == null ? null : categoryId,
"start_date": startDate == null ? null : startDate.toIso8601String(),
"end_date": endDate == null ? null : endDate.toIso8601String(),
"is_active": isActive == null ? null : isActive,
"product_name": productName == null ? null : productName,
};
}
class TopProductsList {
String productId;
String productName;
String catId;
String modeOfSale;
String productSku;
String productMsrp;
String productMrp;
String productImage;
String productQuantity;
Status status;
String productBrand;
String isNew;
String disc;
String outOfStock;
TopProductsList({
this.productId,
this.productName,
this.catId,
this.modeOfSale,
this.productSku,
this.productMsrp,
this.productMrp,
this.productImage,
this.productQuantity,
this.status,
this.productBrand,
this.isNew,
this.disc,
this.outOfStock,
});
factory TopProductsList.fromJson(Map<String, dynamic> json) => TopProductsList(
productId: json["product_id"] == null ? null : json["product_id"],
productName: json["product_name"] == null ? null : json["product_name"],
catId: json["cat_id"] == null ? null : json["cat_id"],
modeOfSale: json["mode_of_sale"] == null ? null : json["mode_of_sale"],
productSku: json["product_sku"] == null ? null : json["product_sku"],
productMsrp: json["product_msrp"] == null ? null : json["product_msrp"],
productMrp: json["product_mrp"] == null ? null : json["product_mrp"],
productImage: json["product_image"] == null ? null : json["product_image"],
productQuantity: json["product_quantity"] == null ? null : json["product_quantity"],
status: json["status"] == null ? null : statusValues.map[json["status"]],
productBrand: json["product_brand"] == null ? null : json["product_brand"],
isNew: json["is_new"] == null ? null : json["is_new"],
disc: json["disc"] == null ? null : json["disc"],
outOfStock: json["out_of_stock"] == null ? null : json["out_of_stock"],
);
Map<String, dynamic> toJson() => {
"product_id": productId == null ? null : productId,
"product_name": productName == null ? null : productName,
"cat_id": catId == null ? null : catId,
"mode_of_sale": modeOfSale == null ? null : modeOfSale,
"product_sku": productSku == null ? null : productSku,
"product_msrp": productMsrp == null ? null : productMsrp,
"product_mrp": productMrp == null ? null : productMrp,
"product_image": productImage == null ? null : productImage,
"product_quantity": productQuantity == null ? null : productQuantity,
"status": status == null ? null : statusValues.reverse[status],
"product_brand": productBrand == null ? null : productBrand,
"is_new": isNew == null ? null : isNew,
"disc": disc == null ? null : disc,
"out_of_stock": outOfStock == null ? null : outOfStock,
};
}
enum Status { ACTIVE }
final statusValues = EnumValues({
"Active": Status.ACTIVE
});
class EnumValues<T> {
Map<String, T> map;
Map<T, String> reverseMap;
EnumValues(this.map);
Map<T, String> get reverse {
if (reverseMap == null) {
reverseMap = map.map((k, v) => new MapEntry(v, k));
}
return reverseMap;
}
}
full code
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
// To parse this JSON data, do
//
// final home = homeFromJson(jsonString);
import 'dart:convert';
Home homeFromJson(String str) => Home.fromJson(json.decode(str));
String homeToJson(Home data) => json.encode(data.toJson());
class Home {
String error;
String message;
Data data;
Home({
this.error,
this.message,
this.data,
});
factory Home.fromJson(Map<String, dynamic> json) => Home(
error: json["error"] == null ? null : json["error"],
message: json["message"] == null ? null : json["message"],
data: json["data"] == null ? null : Data.fromJson(json["data"]),
);
Map<String, dynamic> toJson() => {
"error": error == null ? null : error,
"message": message == null ? null : message,
"data": data == null ? null : data.toJson(),
};
}
class Data {
List<Banner> advBanner;
List<Banner> banner;
List<DealBanner> dealBanner;
List<TopProductsList> topProductsList;
List<TopProductsList> trending;
Data({
this.advBanner,
this.banner,
this.dealBanner,
this.topProductsList,
this.trending,
});
factory Data.fromJson(Map<String, dynamic> json) => Data(
advBanner: json["adv_banner"] == null ? null : List<Banner>.from(json["adv_banner"].map((x) => Banner.fromJson(x))),
banner: json["banner"] == null ? null : List<Banner>.from(json["banner"].map((x) => Banner.fromJson(x))),
dealBanner: json["deal_banner"] == null ? null : List<DealBanner>.from(json["deal_banner"].map((x) => DealBanner.fromJson(x))),
topProductsList: json["top_products_list"] == null ? null : List<TopProductsList>.from(json["top_products_list"].map((x) => TopProductsList.fromJson(x))),
trending: json["trending"] == null ? null : List<TopProductsList>.from(json["trending"].map((x) => TopProductsList.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"adv_banner": advBanner == null ? null : List<dynamic>.from(advBanner.map((x) => x.toJson())),
"banner": banner == null ? null : List<dynamic>.from(banner.map((x) => x.toJson())),
"deal_banner": dealBanner == null ? null : List<dynamic>.from(dealBanner.map((x) => x.toJson())),
"top_products_list": topProductsList == null ? null : List<dynamic>.from(topProductsList.map((x) => x.toJson())),
"trending": trending == null ? null : List<dynamic>.from(trending.map((x) => x.toJson())),
};
}
class Banner {
String bannerImage;
String bannerUrl;
String bannerType;
String productId;
String categoryId;
DateTime startDate;
DateTime endDate;
String isActive;
Banner({
this.bannerImage,
this.bannerUrl,
this.bannerType,
this.productId,
this.categoryId,
this.startDate,
this.endDate,
this.isActive,
});
factory Banner.fromJson(Map<String, dynamic> json) => Banner(
bannerImage: json["banner_image"] == null ? null : json["banner_image"],
bannerUrl: json["banner_url"] == null ? null : json["banner_url"],
bannerType: json["banner_type"] == null ? null : json["banner_type"],
productId: json["product_id"] == null ? null : json["product_id"],
categoryId: json["category_id"] == null ? null : json["category_id"],
startDate: json["start_date"] == null ? null : DateTime.parse(json["start_date"]),
endDate: json["end_date"] == null ? null : DateTime.parse(json["end_date"]),
isActive: json["is_active"] == null ? null : json["is_active"],
);
Map<String, dynamic> toJson() => {
"banner_image": bannerImage == null ? null : bannerImage,
"banner_url": bannerUrl == null ? null : bannerUrl,
"banner_type": bannerType == null ? null : bannerType,
"product_id": productId == null ? null : productId,
"category_id": categoryId == null ? null : categoryId,
"start_date": startDate == null ? null : startDate.toIso8601String(),
"end_date": endDate == null ? null : endDate.toIso8601String(),
"is_active": isActive == null ? null : isActive,
};
}
class DealBanner {
String bnrMessage;
String bannerId;
String bannerImage;
String bannerUrl;
String bannerType;
String productId;
String categoryId;
DateTime startDate;
DateTime endDate;
String isActive;
String productName;
DealBanner({
this.bnrMessage,
this.bannerId,
this.bannerImage,
this.bannerUrl,
this.bannerType,
this.productId,
this.categoryId,
this.startDate,
this.endDate,
this.isActive,
this.productName,
});
factory DealBanner.fromJson(Map<String, dynamic> json) => DealBanner(
bnrMessage: json["bnr_message"] == null ? null : json["bnr_message"],
bannerId: json["banner_id"] == null ? null : json["banner_id"],
bannerImage: json["banner_image"] == null ? null : json["banner_image"],
bannerUrl: json["banner_url"] == null ? null : json["banner_url"],
bannerType: json["banner_type"] == null ? null : json["banner_type"],
productId: json["product_id"] == null ? null : json["product_id"],
categoryId: json["category_id"] == null ? null : json["category_id"],
startDate: json["start_date"] == null ? null : DateTime.parse(json["start_date"]),
endDate: json["end_date"] == null ? null : DateTime.parse(json["end_date"]),
isActive: json["is_active"] == null ? null : json["is_active"],
productName: json["product_name"] == null ? null : json["product_name"],
);
Map<String, dynamic> toJson() => {
"bnr_message": bnrMessage == null ? null : bnrMessage,
"banner_id": bannerId == null ? null : bannerId,
"banner_image": bannerImage == null ? null : bannerImage,
"banner_url": bannerUrl == null ? null : bannerUrl,
"banner_type": bannerType == null ? null : bannerType,
"product_id": productId == null ? null : productId,
"category_id": categoryId == null ? null : categoryId,
"start_date": startDate == null ? null : startDate.toIso8601String(),
"end_date": endDate == null ? null : endDate.toIso8601String(),
"is_active": isActive == null ? null : isActive,
"product_name": productName == null ? null : productName,
};
}
class TopProductsList {
String productId;
String productName;
String catId;
String modeOfSale;
String productSku;
String productMsrp;
String productMrp;
String productImage;
String productQuantity;
Status status;
String productBrand;
String isNew;
String disc;
String outOfStock;
TopProductsList({
this.productId,
this.productName,
this.catId,
this.modeOfSale,
this.productSku,
this.productMsrp,
this.productMrp,
this.productImage,
this.productQuantity,
this.status,
this.productBrand,
this.isNew,
this.disc,
this.outOfStock,
});
factory TopProductsList.fromJson(Map<String, dynamic> json) => TopProductsList(
productId: json["product_id"] == null ? null : json["product_id"],
productName: json["product_name"] == null ? null : json["product_name"],
catId: json["cat_id"] == null ? null : json["cat_id"],
modeOfSale: json["mode_of_sale"] == null ? null : json["mode_of_sale"],
productSku: json["product_sku"] == null ? null : json["product_sku"],
productMsrp: json["product_msrp"] == null ? null : json["product_msrp"],
productMrp: json["product_mrp"] == null ? null : json["product_mrp"],
productImage: json["product_image"] == null ? null : json["product_image"],
productQuantity: json["product_quantity"] == null ? null : json["product_quantity"],
status: json["status"] == null ? null : statusValues.map[json["status"]],
productBrand: json["product_brand"] == null ? null : json["product_brand"],
isNew: json["is_new"] == null ? null : json["is_new"],
disc: json["disc"] == null ? null : json["disc"],
outOfStock: json["out_of_stock"] == null ? null : json["out_of_stock"],
);
Map<String, dynamic> toJson() => {
"product_id": productId == null ? null : productId,
"product_name": productName == null ? null : productName,
"cat_id": catId == null ? null : catId,
"mode_of_sale": modeOfSale == null ? null : modeOfSale,
"product_sku": productSku == null ? null : productSku,
"product_msrp": productMsrp == null ? null : productMsrp,
"product_mrp": productMrp == null ? null : productMrp,
"product_image": productImage == null ? null : productImage,
"product_quantity": productQuantity == null ? null : productQuantity,
"status": status == null ? null : statusValues.reverse[status],
"product_brand": productBrand == null ? null : productBrand,
"is_new": isNew == null ? null : isNew,
"disc": disc == null ? null : disc,
"out_of_stock": outOfStock == null ? null : outOfStock,
};
}
enum Status { ACTIVE }
final statusValues = EnumValues({
"Active": Status.ACTIVE
});
class EnumValues<T> {
Map<String, T> map;
Map<T, String> reverseMap;
EnumValues(this.map);
Map<T, String> get reverse {
if (reverseMap == null) {
reverseMap = map.map((k, v) => new MapEntry(v, k));
}
return reverseMap;
}
}
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
Home home;
int _counter = 0;
void _incrementCounter() {
setState(() {
loadJson();
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
home == null ? Container() : Text(home.data.dealBanner[0].bannerImage),
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
loadJson() async {
//String fileText = await rootBundle.loadString('assets/help.html');
String url = 'http://f12amid08.umc.com/Android/json.txt';
Response response = await get(url);
// sample info available in response
String jsonString = response.body;
home = homeFromJson(jsonString);
print(home.data.dealBanner[0].bannerImage);
print(' topProductsList ${home.data.topProductsList.length}');
print(' dealBanner ${home.data.dealBanner.length}');
print(' trending ${home.data.trending.length}');
}
}
print list length to prove work fine
I/flutter ( 5570): topProductsList 14
I/flutter ( 5570): dealBanner 1
I/flutter ( 5570): trending 13
Upvotes: 3
Reputation: 705
class HomeEntity {
HomeData data;
String error;
String message;
HomeEntity({this.data, this.error, this.message});
HomeEntity.fromJson(Map<String, dynamic> json) {
data = json['data'] != null ? new HomeData.fromJson(json['data']) : null;
error = json['error'];
message = json['message'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.data != null) {
data['data'] = this.data.toJson();
}
data['error'] = this.error;
data['message'] = this.message;
return data;
}
}
class HomeData {
List<HomeDataTrending> trending;
List<HomeDataAdvBanner> advBanner;
List<HomeDataBanner> banner;
List<HomeDataTopProductsList> topProductsList;
List<HomeDataDealBanner> dealBanner;
HomeData({this.trending, this.advBanner, this.banner, this.topProductsList, this.dealBanner});
HomeData.fromJson(Map<String, dynamic> json) {
if (json['trending'] != null) {
trending = new List<HomeDataTrending>();(json['trending'] as List).forEach((v) { trending.add(new HomeDataTrending.fromJson(v)); });
}
if (json['adv_banner'] != null) {
advBanner = new List<HomeDataAdvBanner>();(json['adv_banner'] as List).forEach((v) { advBanner.add(new HomeDataAdvBanner.fromJson(v)); });
}
if (json['banner'] != null) {
banner = new List<HomeDataBanner>();(json['banner'] as List).forEach((v) { banner.add(new HomeDataBanner.fromJson(v)); });
}
if (json['top_products_list'] != null) {
topProductsList = new List<HomeDataTopProductsList>();(json['top_products_list'] as List).forEach((v) { topProductsList.add(new HomeDataTopProductsList.fromJson(v)); });
}
if (json['deal_banner'] != null) {
dealBanner = new List<HomeDataDealBanner>();(json['deal_banner'] as List).forEach((v) { dealBanner.add(new HomeDataDealBanner.fromJson(v)); });
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.trending != null) {
data['trending'] = this.trending.map((v) => v.toJson()).toList();
}
if (this.advBanner != null) {
data['adv_banner'] = this.advBanner.map((v) => v.toJson()).toList();
}
if (this.banner != null) {
data['banner'] = this.banner.map((v) => v.toJson()).toList();
}
if (this.topProductsList != null) {
data['top_products_list'] = this.topProductsList.map((v) => v.toJson()).toList();
}
if (this.dealBanner != null) {
data['deal_banner'] = this.dealBanner.map((v) => v.toJson()).toList();
}
return data;
}
}
class HomeDataTrending {
String productMsrp;
String outOfStock;
String isNew;
String productImage;
String productMrp;
String modeOfSale;
String productName;
String productQuantity;
String productSku;
String productId;
String catId;
String disc;
String productBrand;
String status;
HomeDataTrending({this.productMsrp, this.outOfStock, this.isNew, this.productImage, this.productMrp, this.modeOfSale, this.productName, this.productQuantity, this.productSku, this.productId, this.catId, this.disc, this.productBrand, this.status});
HomeDataTrending.fromJson(Map<String, dynamic> json) {
productMsrp = json['product_msrp'];
outOfStock = json['out_of_stock'];
isNew = json['is_new'];
productImage = json['product_image'];
productMrp = json['product_mrp'];
modeOfSale = json['mode_of_sale'];
productName = json['product_name'];
productQuantity = json['product_quantity'];
productSku = json['product_sku'];
productId = json['product_id'];
catId = json['cat_id'];
disc = json['disc'];
productBrand = json['product_brand'];
status = json['status'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['product_msrp'] = this.productMsrp;
data['out_of_stock'] = this.outOfStock;
data['is_new'] = this.isNew;
data['product_image'] = this.productImage;
data['product_mrp'] = this.productMrp;
data['mode_of_sale'] = this.modeOfSale;
data['product_name'] = this.productName;
data['product_quantity'] = this.productQuantity;
data['product_sku'] = this.productSku;
data['product_id'] = this.productId;
data['cat_id'] = this.catId;
data['disc'] = this.disc;
data['product_brand'] = this.productBrand;
data['status'] = this.status;
return data;
}
}
class HomeDataAdvBanner {
String endDate;
String isActive;
String categoryId;
String bannerType;
String productId;
String bannerUrl;
String bannerImage;
String startDate;
HomeDataAdvBanner({this.endDate, this.isActive, this.categoryId, this.bannerType, this.productId, this.bannerUrl, this.bannerImage, this.startDate});
HomeDataAdvBanner.fromJson(Map<String, dynamic> json) {
endDate = json['end_date'];
isActive = json['is_active'];
categoryId = json['category_id'];
bannerType = json['banner_type'];
productId = json['product_id'];
bannerUrl = json['banner_url'];
bannerImage = json['banner_image'];
startDate = json['start_date'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['end_date'] = this.endDate;
data['is_active'] = this.isActive;
data['category_id'] = this.categoryId;
data['banner_type'] = this.bannerType;
data['product_id'] = this.productId;
data['banner_url'] = this.bannerUrl;
data['banner_image'] = this.bannerImage;
data['start_date'] = this.startDate;
return data;
}
}
class HomeDataBanner {
String endDate;
String isActive;
String categoryId;
String bannerType;
String productId;
String bannerUrl;
String bannerImage;
String startDate;
HomeDataBanner({this.endDate, this.isActive, this.categoryId, this.bannerType, this.productId, this.bannerUrl, this.bannerImage, this.startDate});
HomeDataBanner.fromJson(Map<String, dynamic> json) {
endDate = json['end_date'];
isActive = json['is_active'];
categoryId = json['category_id'];
bannerType = json['banner_type'];
productId = json['product_id'];
bannerUrl = json['banner_url'];
bannerImage = json['banner_image'];
startDate = json['start_date'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['end_date'] = this.endDate;
data['is_active'] = this.isActive;
data['category_id'] = this.categoryId;
data['banner_type'] = this.bannerType;
data['product_id'] = this.productId;
data['banner_url'] = this.bannerUrl;
data['banner_image'] = this.bannerImage;
data['start_date'] = this.startDate;
return data;
}
}
class HomeDataTopProductsList {
String productMsrp;
String outOfStock;
String isNew;
String productImage;
String productMrp;
String modeOfSale;
String productName;
String productQuantity;
String productSku;
String productId;
String catId;
String disc;
String productBrand;
String status;
HomeDataTopProductsList({this.productMsrp, this.outOfStock, this.isNew, this.productImage, this.productMrp, this.modeOfSale, this.productName, this.productQuantity, this.productSku, this.productId, this.catId, this.disc, this.productBrand, this.status});
HomeDataTopProductsList.fromJson(Map<String, dynamic> json) {
productMsrp = json['product_msrp'];
outOfStock = json['out_of_stock'];
isNew = json['is_new'];
productImage = json['product_image'];
productMrp = json['product_mrp'];
modeOfSale = json['mode_of_sale'];
productName = json['product_name'];
productQuantity = json['product_quantity'];
productSku = json['product_sku'];
productId = json['product_id'];
catId = json['cat_id'];
disc = json['disc'];
productBrand = json['product_brand'];
status = json['status'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['product_msrp'] = this.productMsrp;
data['out_of_stock'] = this.outOfStock;
data['is_new'] = this.isNew;
data['product_image'] = this.productImage;
data['product_mrp'] = this.productMrp;
data['mode_of_sale'] = this.modeOfSale;
data['product_name'] = this.productName;
data['product_quantity'] = this.productQuantity;
data['product_sku'] = this.productSku;
data['product_id'] = this.productId;
data['cat_id'] = this.catId;
data['disc'] = this.disc;
data['product_brand'] = this.productBrand;
data['status'] = this.status;
return data;
}
}
class HomeDataDealBanner {
String endDate;
String bnrMessage;
String isActive;
String categoryId;
String bannerId;
String bannerType;
String productId;
String bannerUrl;
String bannerImage;
String productName;
String startDate;
HomeDataDealBanner({this.endDate, this.bnrMessage, this.isActive, this.categoryId, this.bannerId, this.bannerType, this.productId, this.bannerUrl, this.bannerImage, this.productName, this.startDate});
HomeDataDealBanner.fromJson(Map<String, dynamic> json) {
endDate = json['end_date'];
bnrMessage = json['bnr_message'];
isActive = json['is_active'];
categoryId = json['category_id'];
bannerId = json['banner_id'];
bannerType = json['banner_type'];
productId = json['product_id'];
bannerUrl = json['banner_url'];
bannerImage = json['banner_image'];
productName = json['product_name'];
startDate = json['start_date'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['end_date'] = this.endDate;
data['bnr_message'] = this.bnrMessage;
data['is_active'] = this.isActive;
data['category_id'] = this.categoryId;
data['banner_id'] = this.bannerId;
data['banner_type'] = this.bannerType;
data['product_id'] = this.productId;
data['banner_url'] = this.bannerUrl;
data['banner_image'] = this.bannerImage;
data['product_name'] = this.productName;
data['start_date'] = this.startDate;
return data;
}
}
Upvotes: 0
Reputation: 705
Please add your code where you calling the API, So we can understand bit more. If possible try to check null before the you parse the data. And try to add the ProgressBar till the response comes.
Upvotes: 0