i want to parse the json and setting the response into model class. but i stucked here. any help
var data = json.decode(response.body);
//var rest = data["NearbySalons_deals"];
//print(rest);
var rest = data['NearbySalons_deals'];
print(rest);
var offersjson = rest['Offers'] as List;
print(offersjson);
list = rest<NewTabDetailsModel>((json) => NewTabDetailsModel.fromJson(json));
My Model class ::
import 'package:artistry/main.dart';
import 'package:flutter/material.dart';
class NewTabDetailsModel {
int vendorID;
String vendorName;
String vendorDescription;
String contactNo;
String area;
String address;
double latitude;
double longitude;
int avgRating;
int ratingCount;
String logoURL;
List<String> images;
String categories;
String openTime;
String closeTime;
String createdAt;
String updatedAt;
List<Offers> offers;
NewTabDetailsModel(
{this.vendorID,
this.vendorName,
this.vendorDescription,
this.contactNo,
this.area,
this.address,
this.latitude,
this.longitude,
this.avgRating,
this.ratingCount,
this.logoURL,
this.images,
this.categories,
this.openTime,
this.closeTime,
this.createdAt,
this.updatedAt,
this.offers});
NewTabDetailsModel.fromJson(Map<String, dynamic> json) {
vendorID = json['VendorID'];
vendorName = json['VendorName'];
vendorDescription = json['VendorDescription'];
contactNo = json['ContactNo'];
area = json['Area'];
address = json['Address'];
latitude = json['Latitude'];
longitude = json['Longitude'];
avgRating = json['AvgRating'];
ratingCount = json['RatingCount'];
logoURL = json['LogoURL'];
images = json['Images'].cast<String>();
categories = json['Categories'];
openTime = json['OpenTime'];
closeTime = json['CloseTime'];
createdAt = json['CreatedAt'];
updatedAt = json['UpdatedAt'];
if (json['Offers'] != null) {
offers = new List<Offers>();
json['Offers'].forEach((v) {
offers.add(new Offers.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['VendorID'] = this.vendorID;
data['VendorName'] = this.vendorName;
data['VendorDescription'] = this.vendorDescription;
data['ContactNo'] = this.contactNo;
data['Area'] = this.area;
data['Address'] = this.address;
data['Latitude'] = this.latitude;
data['Longitude'] = this.longitude;
data['AvgRating'] = this.avgRating;
data['RatingCount'] = this.ratingCount;
data['LogoURL'] = this.logoURL;
data['Images'] = this.images;
data['Categories'] = this.categories;
data['OpenTime'] = this.openTime;
data['CloseTime'] = this.closeTime;
data['CreatedAt'] = this.createdAt;
data['UpdatedAt'] = this.updatedAt;
if (this.offers != null) {
data['Offers'] = this.offers.map((v) => v.toJson()).toList();
}
return data;
}
}
class Offers {
int offerID;
int vendorID;
int categoryID;
String offerTitle;
String description;
int offerPercentage;
String fromDateTime;
String toDateTime;
int actualPrice;
int offerPrice;
int status;
int qty;
String createdAt;
String updatedAt;
Offers(
{this.offerID,
this.vendorID,
this.categoryID,
this.offerTitle,
this.description,
this.offerPercentage,
this.fromDateTime,
this.toDateTime,
this.actualPrice,
this.offerPrice,
this.status,
this.qty,
this.createdAt,
this.updatedAt});
Offers.fromJson(Map<String, dynamic> json) {
offerID = json['OfferID'];
vendorID = json['VendorID'];
categoryID = json['CategoryID'];
offerTitle = json['OfferTitle'];
description = json['Description'];
offerPercentage = json['OfferPercentage'];
fromDateTime = json['FromDateTime'];
toDateTime = json['ToDateTime'];
actualPrice = json['ActualPrice'];
offerPrice = json['OfferPrice'];
status = json['Status'];
qty = json['Qty'];
createdAt = json['CreatedAt'];
updatedAt = json['UpdatedAt'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['OfferID'] = this.offerID;
data['VendorID'] = this.vendorID;
data['CategoryID'] = this.categoryID;
data['OfferTitle'] = this.offerTitle;
data['Description'] = this.description;
data['OfferPercentage'] = this.offerPercentage;
data['FromDateTime'] = this.fromDateTime;
data['ToDateTime'] = this.toDateTime;
data['ActualPrice'] = this.actualPrice;
data['OfferPrice'] = this.offerPrice;
data['Status'] = this.status;
data['Qty'] = this.qty;
data['CreatedAt'] = this.createdAt;
data['UpdatedAt'] = this.updatedAt;
return data;
}
}