#flutter #dart
Вопрос:
Я извлекаю данные api, ниже приведен пример данных json. Я могу распечатать данные sunday
, но как мне распечатать конкретные данные, внутри sunday
которых 06:00
Модель
class DetailsDataBranchesSchedule {
String? id;
String? sunday;
String? monday;
String? tuesday;
String? wednesday;
String? thursday;
String? friday;
String? saturday;
String? createdAt;
String? updatedAt;
String? branchId;
DetailsDataBranchesSchedule({
this.id,
this.sunday,
this.monday,
this.tuesday,
this.wednesday,
this.thursday,
this.friday,
this.saturday,
this.createdAt,
this.updatedAt,
this.branchId,
});
DetailsDataBranchesSchedule.fromJson(Map<String, dynamic> json) {
id = json["id"]?.toString();
sunday = json["sunday"]?.toString();
monday = json["monday"]?.toString();
tuesday = json["tuesday"]?.toString();
wednesday = json["wednesday"]?.toString();
thursday = json["thursday"]?.toString();
friday = json["friday"]?.toString();
saturday = json["saturday"]?.toString();
createdAt = json["createdAt"]?.toString();
updatedAt = json["updatedAt"]?.toString();
branchId = json["branchId"]?.toString();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data["id"] = id;
data["sunday"] = sunday;
data["monday"] = monday;
data["tuesday"] = tuesday;
data["wednesday"] = wednesday;
data["thursday"] = thursday;
data["friday"] = friday;
data["saturday"] = saturday;
data["createdAt"] = createdAt;
data["updatedAt"] = updatedAt;
data["branchId"] = branchId;
return data;
}
}
class DetailsDataRestaurantRestaurantsLocales {
String? id;
String? name;
String? aboutUs;
String? address;
String? lang;
String? createdAt;
String? updatedAt;
String? restaurantId;
DetailsDataRestaurantRestaurantsLocales({
this.id,
this.name,
this.aboutUs,
this.address,
this.lang,
this.createdAt,
this.updatedAt,
this.restaurantId,
});
DetailsDataRestaurantRestaurantsLocales.fromJson(Map<String, dynamic> json) {
id = json["id"]?.toString();
name = json["name"]?.toString();
aboutUs = json["about_us"]?.toString();
address = json["address"]?.toString();
lang = json["lang"]?.toString();
createdAt = json["createdAt"]?.toString();
updatedAt = json["updatedAt"]?.toString();
restaurantId = json["restaurantId"]?.toString();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data["id"] = id;
data["name"] = name;
data["about_us"] = aboutUs;
data["address"] = address;
data["lang"] = lang;
data["createdAt"] = createdAt;
data["updatedAt"] = updatedAt;
data["restaurantId"] = restaurantId;
return data;
}
}
class DetailsDataRestaurant {
String? id;
String? phoneNumber;
String? email;
String? latitude;
String? longitude;
String? image;
String? restaurantRegisterDocument;
int? status;
int? addedBy;
int? updatedBy;
bool? isDeleted;
String? createdAt;
String? updatedAt;
String? restaurantTypeId;
List<DetailsDataRestaurantRestaurantsLocales?>? restaurantsLocales;
DetailsDataRestaurant({
this.id,
this.phoneNumber,
this.email,
this.latitude,
this.longitude,
this.image,
this.restaurantRegisterDocument,
this.status,
this.addedBy,
this.updatedBy,
this.isDeleted,
this.createdAt,
this.updatedAt,
this.restaurantTypeId,
this.restaurantsLocales,
});
DetailsDataRestaurant.fromJson(Map<String, dynamic> json) {
id = json["id"]?.toString();
phoneNumber = json["phone_number"]?.toString();
email = json["email"]?.toString();
latitude = json["latitude"]?.toString();
longitude = json["longitude"]?.toString();
image = json["image"]?.toString();
restaurantRegisterDocument =
json["restaurant_register_document"]?.toString();
status = json["status"]?.toInt();
addedBy = json["added_by"]?.toInt();
updatedBy = json["updated_by"]?.toInt();
isDeleted = json["is_deleted"];
createdAt = json["createdAt"]?.toString();
updatedAt = json["updatedAt"]?.toString();
restaurantTypeId = json["restaurantTypeId"]?.toString();
if (json["restaurants_locales"] != null) {
final v = json["restaurants_locales"];
final arr0 = <DetailsDataRestaurantRestaurantsLocales>[];
v.forEach((v) {
arr0.add(DetailsDataRestaurantRestaurantsLocales.fromJson(v));
});
restaurantsLocales = arr0;
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data["id"] = id;
data["phone_number"] = phoneNumber;
data["email"] = email;
data["latitude"] = latitude;
data["longitude"] = longitude;
data["image"] = image;
data["restaurant_register_document"] = restaurantRegisterDocument;
data["status"] = status;
data["added_by"] = addedBy;
data["updated_by"] = updatedBy;
data["is_deleted"] = isDeleted;
data["createdAt"] = createdAt;
data["updatedAt"] = updatedAt;
data["restaurantTypeId"] = restaurantTypeId;
if (restaurantsLocales != null) {
final v = restaurantsLocales;
final arr0 = [];
v!.forEach((v) {
arr0.add(v!.toJson());
});
data["restaurants_locales"] = arr0;
}
return data;
}
}
class DetailsDataDistrictDistrictsLocales {
String? id;
String? name;
String? lang;
String? createdAt;
String? updatedAt;
String? districtId;
DetailsDataDistrictDistrictsLocales({
this.id,
this.name,
this.lang,
this.createdAt,
this.updatedAt,
this.districtId,
});
DetailsDataDistrictDistrictsLocales.fromJson(Map<String, dynamic> json) {
id = json["id"]?.toString();
name = json["name"]?.toString();
lang = json["lang"]?.toString();
createdAt = json["createdAt"]?.toString();
updatedAt = json["updatedAt"]?.toString();
districtId = json["districtId"]?.toString();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data["id"] = id;
data["name"] = name;
data["lang"] = lang;
data["createdAt"] = createdAt;
data["updatedAt"] = updatedAt;
data["districtId"] = districtId;
return data;
}
}
class DetailsDataDistrict {
String? id;
bool? isDeleted;
String? createdAt;
String? updatedAt;
String? cityId;
List<DetailsDataDistrictDistrictsLocales?>? districtsLocales;
DetailsDataDistrict({
this.id,
this.isDeleted,
this.createdAt,
this.updatedAt,
this.cityId,
this.districtsLocales,
});
DetailsDataDistrict.fromJson(Map<String, dynamic> json) {
id = json["id"]?.toString();
isDeleted = json["is_deleted"];
createdAt = json["createdAt"]?.toString();
updatedAt = json["updatedAt"]?.toString();
cityId = json["cityId"]?.toString();
if (json["districts_locales"] != null) {
final v = json["districts_locales"];
final arr0 = <DetailsDataDistrictDistrictsLocales>[];
v.forEach((v) {
arr0.add(DetailsDataDistrictDistrictsLocales.fromJson(v));
});
districtsLocales = arr0;
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data["id"] = id;
data["is_deleted"] = isDeleted;
data["createdAt"] = createdAt;
data["updatedAt"] = updatedAt;
data["cityId"] = cityId;
if (districtsLocales != null) {
final v = districtsLocales;
final arr0 = [];
v!.forEach((v) {
arr0.add(v!.toJson());
});
data["districts_locales"] = arr0;
}
return data;
}
}
class DetailsDataCityCitiesLocales {
String? id;
String? name;
String? lang;
String? createdAt;
String? updatedAt;
String? cityId;
DetailsDataCityCitiesLocales({
this.id,
this.name,
this.lang,
this.createdAt,
this.updatedAt,
this.cityId,
});
DetailsDataCityCitiesLocales.fromJson(Map<String, dynamic> json) {
id = json["id"]?.toString();
name = json["name"]?.toString();
lang = json["lang"]?.toString();
createdAt = json["createdAt"]?.toString();
updatedAt = json["updatedAt"]?.toString();
cityId = json["cityId"]?.toString();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data["id"] = id;
data["name"] = name;
data["lang"] = lang;
data["createdAt"] = createdAt;
data["updatedAt"] = updatedAt;
data["cityId"] = cityId;
return data;
}
}
class DetailsDataCity {
String? id;
String? code;
int? status;
bool? isDeleted;
String? createdAt;
String? updatedAt;
String? countryId;
List<DetailsDataCityCitiesLocales?>? citiesLocales;
DetailsDataCity({
this.id,
this.code,
this.status,
this.isDeleted,
this.createdAt,
this.updatedAt,
this.countryId,
this.citiesLocales,
});
DetailsDataCity.fromJson(Map<String, dynamic> json) {
id = json["id"]?.toString();
code = json["code"]?.toString();
status = json["status"]?.toInt();
isDeleted = json["is_deleted"];
createdAt = json["createdAt"]?.toString();
updatedAt = json["updatedAt"]?.toString();
countryId = json["countryId"]?.toString();
if (json["cities_locales"] != null) {
final v = json["cities_locales"];
final arr0 = <DetailsDataCityCitiesLocales>[];
v.forEach((v) {
arr0.add(DetailsDataCityCitiesLocales.fromJson(v));
});
citiesLocales = arr0;
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data["id"] = id;
data["code"] = code;
data["status"] = status;
data["is_deleted"] = isDeleted;
data["createdAt"] = createdAt;
data["updatedAt"] = updatedAt;
data["countryId"] = countryId;
if (citiesLocales != null) {
final v = citiesLocales;
final arr0 = [];
v!.forEach((v) {
arr0.add(v!.toJson());
});
data["cities_locales"] = arr0;
}
return data;
}
}
class DetailsDataBranchesLocales {
String? id;
String? name;
String? description;
String? address;
String? lang;
String? createdAt;
String? updatedAt;
String? branchId;
DetailsDataBranchesLocales({
this.id,
this.name,
this.description,
this.address,
this.lang,
this.createdAt,
this.updatedAt,
this.branchId,
});
DetailsDataBranchesLocales.fromJson(Map<String, dynamic> json) {
id = json["id"]?.toString();
name = json["name"]?.toString();
description = json["description"]?.toString();
address = json["address"]?.toString();
lang = json["lang"]?.toString();
createdAt = json["createdAt"]?.toString();
updatedAt = json["updatedAt"]?.toString();
branchId = json["branchId"]?.toString();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data["id"] = id;
data["name"] = name;
data["description"] = description;
data["address"] = address;
data["lang"] = lang;
data["createdAt"] = createdAt;
data["updatedAt"] = updatedAt;
data["branchId"] = branchId;
return data;
}
}
class DetailsData {
String? id;
String? email;
String? phoneNumber;
String? latitude;
String? longitude;
String? photo;
String? countryCode;
int? status;
bool? hasParking;
String? instruction;
bool? isActive;
bool? isDeleted;
int? addedBy;
int? updatedBy;
String? createdAt;
String? updatedAt;
String? restaurantId;
String? cityId;
String? districtId;
List<DetailsDataBranchesLocales?>? branchesLocales;
DetailsDataCity? city;
DetailsDataDistrict? district;
DetailsDataRestaurant? restaurant;
DetailsDataBranchesSchedule? branchesSchedule;
DetailsData({
this.id,
this.email,
this.phoneNumber,
this.latitude,
this.longitude,
this.photo,
this.countryCode,
this.status,
this.hasParking,
this.instruction,
this.isActive,
this.isDeleted,
this.addedBy,
this.updatedBy,
this.createdAt,
this.updatedAt,
this.restaurantId,
this.cityId,
this.districtId,
this.branchesLocales,
this.city,
this.district,
this.restaurant,
this.branchesSchedule,
});
DetailsData.fromJson(Map<String, dynamic> json) {
id = json["id"]?.toString();
email = json["email"]?.toString();
phoneNumber = json["phone_number"]?.toString();
latitude = json["latitude"]?.toString();
longitude = json["longitude"]?.toString();
photo = json["photo"]?.toString();
countryCode = json["country_code"]?.toString();
status = json["status"]?.toInt();
hasParking = json["has_parking"];
instruction = json["instruction"]?.toString();
isActive = json["isActive"];
isDeleted = json["isDeleted"];
addedBy = json["added_by"]?.toInt();
updatedBy = json["updated_by"]?.toInt();
createdAt = json["createdAt"]?.toString();
updatedAt = json["updatedAt"]?.toString();
restaurantId = json["restaurantId"]?.toString();
cityId = json["cityId"]?.toString();
districtId = json["districtId"]?.toString();
if (json["branches_locales"] != null) {
final v = json["branches_locales"];
final arr0 = <DetailsDataBranchesLocales>[];
v.forEach((v) {
arr0.add(DetailsDataBranchesLocales.fromJson(v));
});
branchesLocales = arr0;
}
city =
(json["city"] != null) ? DetailsDataCity.fromJson(json["city"]) : null;
district = (json["district"] != null)
? DetailsDataDistrict.fromJson(json["district"])
: null;
restaurant = (json["restaurant"] != null)
? DetailsDataRestaurant.fromJson(json["restaurant"])
: null;
branchesSchedule = (json["branches_schedule"] != null)
? DetailsDataBranchesSchedule.fromJson(json["branches_schedule"])
: null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data["id"] = id;
data["email"] = email;
data["phone_number"] = phoneNumber;
data["latitude"] = latitude;
data["longitude"] = longitude;
data["photo"] = photo;
data["country_code"] = countryCode;
data["status"] = status;
data["has_parking"] = hasParking;
data["instruction"] = instruction;
data["isActive"] = isActive;
data["isDeleted"] = isDeleted;
data["added_by"] = addedBy;
data["updated_by"] = updatedBy;
data["createdAt"] = createdAt;
data["updatedAt"] = updatedAt;
data["restaurantId"] = restaurantId;
data["cityId"] = cityId;
data["districtId"] = districtId;
if (branchesLocales != null) {
final v = branchesLocales;
final arr0 = [];
v!.forEach((v) {
arr0.add(v!.toJson());
});
data["branches_locales"] = arr0;
}
if (city != null) {
data["city"] = city!.toJson();
}
if (district != null) {
data["district"] = district!.toJson();
}
if (restaurant != null) {
data["restaurant"] = restaurant!.toJson();
}
if (branchesSchedule != null) {
data["branches_schedule"] = branchesSchedule!.toJson();
}
return data;
}
}
class Details {
String? message;
DetailsData? data;
Details({
this.message,
this.data,
});
Details.fromJson(Map<String, dynamic> json) {
message = json["message"]?.toString();
data = (json["data"] != null) ? DetailsData.fromJson(json["data"]) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data["message"] = message;
if (data != null) {
data["data"] = this.data!.toJson();
}
return data;
}
}
JSON
"branches_schedule": {
"id": "1",
"sunday": "{"opens_at":"06:00","closes_at":"24:00"}",
"monday": "{"opens_at":"06:00","closes_at":"24:00"}",
"tuesday": "{"opens_at":"06:00","closes_at":"24:00"}",
"wednesday": "{"opens_at":"06:00","closes_at":"24:00"}",
"thursday": "{"opens_at":"06:00","closes_at":"24:00"}",
"friday": "{"opens_at":"08:00","closes_at":"22:00"}",
"saturday": "{"opens_at":"08:00","closes_at":"22:00"}",
"createdAt": "2021-09-09T13:45:30.656Z",
"updatedAt": "2021-09-09T13:45:30.656Z",
"branchId": "10"
}
Дротик
print(data.data!.branchesSchedule!.sunday!) // How to print 06:00