我对Flutter并不陌生,现在正在开发一个列出餐厅的应用。 我有一个API端点,可返回JSON数据。这里是:https://node.coredes.in/restaurants。
我已经完成布局了。但是我不知道如何处理JSON数据。我已经尝试从网上获得的示例中做到这一点。
我想知道如何使用这些字段-doc.name,doc.image_gallery [0],doc.location.locality,doc.friday.closing_at.hour,doc.friday.closing_at.minute创建卡列表?
有人可以帮我提供示例代码吗?
答案 0 :(得分:1)
尝试一下:
class DemoClass {
String name;
int Id;
DemoClass(this.name, this.Id);
static DemoClass fromJson(Map<String, dynamic> json) {
return DemoClass(json['name'] as String, json['Id'] as int);
}
Map<String, dynamic> toJson(DemoClass instance) =>
<String, dynamic>{
'name': instance.name,
'Id': instance.trackerId
};
static List<DemoClass> fromJsonListStr(String jsonStr){
var list = jsonDecode(jsonStr) as List;
List<DemoClass> myThing = list.map((e) => DemoClass.fromJson(e)).toList();
return myThing;
}
}
使用它来获取对象列表:
var resp = await http.get('http://apicall.com/array',
headers: {"Content-Type": "application/json"});
var ret = DemoClass.fromJsonListStr(resp.body);
return ret;
使用它来获取单个对象:
var resp = await http.get('http://apicall.com/array',
headers: {"Content-Type": "application/json"});
var data = jsonDecode(resp.body);
var obj = DemoClass.fromJson(data);
答案 1 :(得分:1)
以下是示例代码,显示了如何在JSON文件中获取餐厅名称:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'dart:async';
void main() {
runApp(new MaterialApp(
home: new HomePage(),
));
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
String url = "https://node.coredes.in/restaurants/";
List data;
/*onCreate*/
@override
void initState() {
// TODO: implement initState
super.initState();
getJSONData(); //method
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(title: Text("my JSON app")),
body: new ListView.builder(
// itemCount: 1,
//itemCount: data==null ? 0 :data.length ,
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, int index) {
return new Container(
child: new Center(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Card(
child: new Container(
child: new Text(data[index]['name'] ?? ''),
padding: EdgeInsets.all(20),
),
)
],
),
),
);
},
),
);
}
/*method*/ //RT is Future<String>
Future<String> getJSONData() async {
var response = await http
.get(Uri.encodeFull(url), headers: {"Accept": "application/json"});
print(response.body);
debugPrint(response.body);
setState(() {
var convertDataToJson = json.decode(response.body);
data = convertDataToJson['doc'];
});
return "Success";
}
}
您可以玩data[index]['name']
。例如,如果您想要城市,您可以做类似data[index]['location']['city']
的事情。
因此,您说的类模型是为了使您的代码易于理解并且可以快速重用。您的JSON
文件上有一个复杂的嵌入式数据,访问该数据有点困难。因此,无论您希望从中获得什么价值,使用类模型都将非常容易获得。让我向您展示一个具体的示例,要知道餐厅何时开门和关门,您需要遵循doc => opening_times => Sunday => opening_at
的层次结构,关闭时间也要如此。因此,让我们将其转换为颤动代码,如果我们只想获取hour
值,它将类似于data[index]['opening_time']['Sunday']['opening_at']['hour']
,而minute
值则相同,其余所有值都相同。在这个层次结构中,我们花了很长时间才到达终点,但是您可以随意想象一个非常大的层次结构,情况将如何。让我们回到我们的案例,现在让我们以相同的示例为例,尝试使用一个类模型,而不是硬编码的JSON
属性。让我们为Restaurant
写一个模型类。
class Restaurant {
String name;
String city;
String day;
bool isOpen;
int hourOpen;
int minuteOpen;
// ..
// ..
// The rest of your wanted attributs
Restaurant(
{this.name,
this.city,
this.day,
this.isOpen,
this.hourOpen,
this.minuteOpen});
}
在那之后,我们将编写一个方法,其主要目标是填充我们的餐厅变量。
Future<String> getRestaurants() async {
var response = await http
.get(Uri.encodeFull(url), headers: {"Accept": "application/json"});
var convertDataToJson = json.decode(response.body);
data = convertDataToJson['doc'];
List tempRestaurants = new List();
data.forEach((restaurant) => {
tempRestaurants.add(new Restaurant(
name: restaurant['name'],
city: restaurant['location']['city'],
day: 'Sunday',
isOpen: restaurant['opening_times']['Sunday']['is_open_today'],
hourOpen: restaurant['opening_times']['Sunday']['opening_at']
['hour'],
minuteOpen: restaurant['opening_times']['Sunday']['opening_at']
['minute'])),
});
setState(() {
this.restaurants = tempRestaurants;
});
}
这是我们在编写模型后如何获取数据的方法。
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(title: Text("my JSON app")),
body: new ListView.builder(
itemCount: restaurants == null ? 0 : restaurants.length,
itemBuilder: (BuildContext context, int index) {
return new Container(
child: new Center(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Card(
child: new Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Name: ${restaurants[index].name}"),
Text("City: ${restaurants[index].city}"),
Text("Day: ${restaurants[index].day}"),
Text("IsOpen: ${restaurants[index].isOpen}"),
Text(
"Time: ${restaurants[index].hourOpen}:${restaurants[index].minuteOpen}"),
]),
padding: EdgeInsets.all(20),
),
)
],
),
),
);
},
),
);
}
PS:在此示例中,我只是在每个餐厅实例中获取了Sunday
的值,因此我可以向您展示如何轻松地访问数据。但是您可以为其创建一个类模型,比如说RestaurantDay
,并拥有诸如dayName
,hourOpen
,minuteOpen
等属性。然后,您可以将其链接以及获取数据的逻辑。
答案 2 :(得分:1)
有人可以帮我提供示例代码吗?
根据您的要求,提供示例代码。
import 'dart:convert';
import 'json_objects.dart';
import 'package:http/http.dart' as _http;
Future<void> main() async {
var url = 'https://node.coredes.in/restaurants';
var response = await _http.get(url);
if (response.statusCode == 200) {
var jsonObject = jsonDecode(response.body) as Map;
var response1 = Response1.fromJson(jsonObject);
for (var doc in response1.doc) {
print(doc.name);
if (doc.imageGallery != null) {
for (var image in doc.imageGallery) {
print(' ' + image);
}
}
}
}
}
数据模型非常简单。
// Generated by 'yaml2podo'
// Version: 0.1.11
// https://pub.dev/packages/yaml2podo
class Response1 {
final List<Response1OpeningDetails> openingDetails;
final List<Response1Doc> doc;
final int total;
Response1({this.openingDetails, this.doc, this.total});
factory Response1.fromJson(Map map) {
return Response1(
openingDetails: _toList(map['openingDetails'],
(e) => Response1OpeningDetails.fromJson(e as Map)),
doc: _toList(map['doc'], (e) => Response1Doc.fromJson(e as Map)),
total: map['total'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['openingDetails'] = _fromList(openingDetails, (e) => e.toJson());
result['doc'] = _fromList(doc, (e) => e.toJson());
result['total'] = total;
return result;
}
}
class Response1Doc {
final String website;
final String id_;
final List<String> imageGallery;
final int numberOfBranches;
final String address;
final int discountType;
final DateTime updatedAt;
final Response1DocLocation location;
final List<String> reviews;
final String name;
final List<String> cuisines;
final Response1DocAttributes attributes;
final int costForTwo;
final String permalink;
final double rating;
final String introToRestaurant;
final DateTime createdAt;
final Response1DocTermsAndConditions termsAndConditions;
final String bookingTelephone;
final int v__;
final List<String> serves;
final List<String> features;
final List<String> menu;
final String logo;
final Response1DocOpeningTimes openingTimes;
Response1Doc(
{this.website,
this.id_,
this.imageGallery,
this.numberOfBranches,
this.address,
this.discountType,
this.updatedAt,
this.location,
this.reviews,
this.name,
this.cuisines,
this.attributes,
this.costForTwo,
this.permalink,
this.rating,
this.introToRestaurant,
this.createdAt,
this.termsAndConditions,
this.bookingTelephone,
this.v__,
this.serves,
this.features,
this.menu,
this.logo,
this.openingTimes});
factory Response1Doc.fromJson(Map map) {
return Response1Doc(
website: map['website'] as String,
id_: map['_id'] as String,
imageGallery: _toList(map['image_gallery'], (e) => e as String),
numberOfBranches: map['number_of_branches'] as int,
address: map['address'] as String,
discountType: map['discount_type'] as int,
updatedAt: _toDateTime(map['updatedAt']),
location: _toObject(
map['location'], (e) => Response1DocLocation.fromJson(e as Map)),
reviews: _toList(map['reviews'], (e) => e as String),
name: map['name'] as String,
cuisines: _toList(map['cuisines'], (e) => e as String),
attributes: _toObject(map['attributes'],
(e) => Response1DocAttributes.fromJson(e as Map)),
costForTwo: map['cost_for_two'] as int,
permalink: map['permalink'] as String,
rating: _toDouble(map['rating']),
introToRestaurant: map['intro_to_restaurant'] as String,
createdAt: _toDateTime(map['createdAt']),
termsAndConditions: _toObject(map['terms_and_conditions'],
(e) => Response1DocTermsAndConditions.fromJson(e as Map)),
bookingTelephone: map['booking_telephone'] as String,
v__: map['__v'] as int,
serves: _toList(map['serves'], (e) => e as String),
features: _toList(map['features'], (e) => e as String),
menu: _toList(map['menu'], (e) => e as String),
logo: map['logo'] as String,
openingTimes: _toObject(map['opening_times'],
(e) => Response1DocOpeningTimes.fromJson(e as Map)));
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['website'] = website;
result['_id'] = id_;
result['image_gallery'] = _fromList(imageGallery, (e) => e);
result['number_of_branches'] = numberOfBranches;
result['address'] = address;
result['discount_type'] = discountType;
result['updatedAt'] = _fromDateTime(updatedAt);
result['location'] = location?.toJson();
result['reviews'] = _fromList(reviews, (e) => e);
result['name'] = name;
result['cuisines'] = _fromList(cuisines, (e) => e);
result['attributes'] = attributes?.toJson();
result['cost_for_two'] = costForTwo;
result['permalink'] = permalink;
result['rating'] = rating;
result['intro_to_restaurant'] = introToRestaurant;
result['createdAt'] = _fromDateTime(createdAt);
result['terms_and_conditions'] = termsAndConditions?.toJson();
result['booking_telephone'] = bookingTelephone;
result['__v'] = v__;
result['serves'] = _fromList(serves, (e) => e);
result['features'] = _fromList(features, (e) => e);
result['menu'] = _fromList(menu, (e) => e);
result['logo'] = logo;
result['opening_times'] = openingTimes?.toJson();
return result;
}
}
class Response1DocAttributes {
final bool takeAway;
final List<String> paymentMode;
final bool fridayOffer;
final String venueType;
final bool minimumSpend;
final Response1DocAttributesBookingType bookingType;
final int groupSize;
final bool thursdayOffer;
final bool buffet;
final bool walkIn;
final bool sevenDaysOffer;
Response1DocAttributes(
{this.takeAway,
this.paymentMode,
this.fridayOffer,
this.venueType,
this.minimumSpend,
this.bookingType,
this.groupSize,
this.thursdayOffer,
this.buffet,
this.walkIn,
this.sevenDaysOffer});
factory Response1DocAttributes.fromJson(Map map) {
return Response1DocAttributes(
takeAway: map['take_away'] as bool,
paymentMode: _toList(map['payment_mode'], (e) => e as String),
fridayOffer: map['friday_offer'] as bool,
venueType: map['venue_type'] as String,
minimumSpend: map['minimum_spend'] as bool,
bookingType: _toObject(map['booking_type'],
(e) => Response1DocAttributesBookingType.fromJson(e as Map)),
groupSize: map['group_size'] as int,
thursdayOffer: map['thursday_offer'] as bool,
buffet: map['buffet'] as bool,
walkIn: map['walk_in'] as bool,
sevenDaysOffer: map['seven_days_offer'] as bool);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['take_away'] = takeAway;
result['payment_mode'] = _fromList(paymentMode, (e) => e);
result['friday_offer'] = fridayOffer;
result['venue_type'] = venueType;
result['minimum_spend'] = minimumSpend;
result['booking_type'] = bookingType?.toJson();
result['group_size'] = groupSize;
result['thursday_offer'] = thursdayOffer;
result['buffet'] = buffet;
result['walk_in'] = walkIn;
result['seven_days_offer'] = sevenDaysOffer;
return result;
}
}
class Response1DocAttributesBookingType {
final bool telephone;
final bool walkIn;
Response1DocAttributesBookingType({this.telephone, this.walkIn});
factory Response1DocAttributesBookingType.fromJson(Map map) {
return Response1DocAttributesBookingType(
telephone: map['telephone'] as bool, walkIn: map['walk_in'] as bool);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['telephone'] = telephone;
result['walk_in'] = walkIn;
return result;
}
}
class Response1DocLocation {
final String zip;
final String city;
final double longitude;
final double latitude;
final String locality;
Response1DocLocation(
{this.zip, this.city, this.longitude, this.latitude, this.locality});
factory Response1DocLocation.fromJson(Map map) {
return Response1DocLocation(
zip: map['zip'] as String,
city: map['city'] as String,
longitude: _toDouble(map['longitude']),
latitude: _toDouble(map['latitude']),
locality: map['locality'] as String);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['zip'] = zip;
result['city'] = city;
result['longitude'] = longitude;
result['latitude'] = latitude;
result['locality'] = locality;
return result;
}
}
class Response1DocOpeningTimes {
final Response1DocOpeningTimesTuesday Tuesday;
final Response1DocOpeningTimesFriday Friday;
final Response1DocOpeningTimesMonday Monday;
final Response1DocOpeningTimesSaturday Saturday;
final Response1DocOpeningTimesSunday Sunday;
final Response1DocOpeningTimesWednesday Wednesday;
final Response1DocOpeningTimesThursday Thursday;
Response1DocOpeningTimes(
{this.Tuesday,
this.Friday,
this.Monday,
this.Saturday,
this.Sunday,
this.Wednesday,
this.Thursday});
factory Response1DocOpeningTimes.fromJson(Map map) {
return Response1DocOpeningTimes(
Tuesday: _toObject(map['Tuesday'],
(e) => Response1DocOpeningTimesTuesday.fromJson(e as Map)),
Friday: _toObject(map['Friday'],
(e) => Response1DocOpeningTimesFriday.fromJson(e as Map)),
Monday: _toObject(map['Monday'],
(e) => Response1DocOpeningTimesMonday.fromJson(e as Map)),
Saturday: _toObject(map['Saturday'],
(e) => Response1DocOpeningTimesSaturday.fromJson(e as Map)),
Sunday: _toObject(map['Sunday'],
(e) => Response1DocOpeningTimesSunday.fromJson(e as Map)),
Wednesday: _toObject(map['Wednesday'],
(e) => Response1DocOpeningTimesWednesday.fromJson(e as Map)),
Thursday: _toObject(map['Thursday'],
(e) => Response1DocOpeningTimesThursday.fromJson(e as Map)));
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['Tuesday'] = Tuesday?.toJson();
result['Friday'] = Friday?.toJson();
result['Monday'] = Monday?.toJson();
result['Saturday'] = Saturday?.toJson();
result['Sunday'] = Sunday?.toJson();
result['Wednesday'] = Wednesday?.toJson();
result['Thursday'] = Thursday?.toJson();
return result;
}
}
class Response1DocOpeningTimesFriday {
final Response1DocOpeningTimesFridayClosingAt closingAt;
final bool isOpenToday;
final Response1DocOpeningTimesFridayOpeningAt openingAt;
Response1DocOpeningTimesFriday(
{this.closingAt, this.isOpenToday, this.openingAt});
factory Response1DocOpeningTimesFriday.fromJson(Map map) {
return Response1DocOpeningTimesFriday(
closingAt: _toObject(map['closing_at'],
(e) => Response1DocOpeningTimesFridayClosingAt.fromJson(e as Map)),
isOpenToday: map['is_open_today'] as bool,
openingAt: _toObject(map['opening_at'],
(e) => Response1DocOpeningTimesFridayOpeningAt.fromJson(e as Map)));
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['closing_at'] = closingAt?.toJson();
result['is_open_today'] = isOpenToday;
result['opening_at'] = openingAt?.toJson();
return result;
}
}
class Response1DocOpeningTimesFridayClosingAt {
final int hour;
final int minute;
Response1DocOpeningTimesFridayClosingAt({this.hour, this.minute});
factory Response1DocOpeningTimesFridayClosingAt.fromJson(Map map) {
return Response1DocOpeningTimesFridayClosingAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesFridayOpeningAt {
final int hour;
final int minute;
Response1DocOpeningTimesFridayOpeningAt({this.hour, this.minute});
factory Response1DocOpeningTimesFridayOpeningAt.fromJson(Map map) {
return Response1DocOpeningTimesFridayOpeningAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesMonday {
final Response1DocOpeningTimesMondayClosingAt closingAt;
final bool isOpenToday;
final Response1DocOpeningTimesMondayOpeningAt openingAt;
Response1DocOpeningTimesMonday(
{this.closingAt, this.isOpenToday, this.openingAt});
factory Response1DocOpeningTimesMonday.fromJson(Map map) {
return Response1DocOpeningTimesMonday(
closingAt: _toObject(map['closing_at'],
(e) => Response1DocOpeningTimesMondayClosingAt.fromJson(e as Map)),
isOpenToday: map['is_open_today'] as bool,
openingAt: _toObject(map['opening_at'],
(e) => Response1DocOpeningTimesMondayOpeningAt.fromJson(e as Map)));
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['closing_at'] = closingAt?.toJson();
result['is_open_today'] = isOpenToday;
result['opening_at'] = openingAt?.toJson();
return result;
}
}
class Response1DocOpeningTimesMondayClosingAt {
final int hour;
final int minute;
Response1DocOpeningTimesMondayClosingAt({this.hour, this.minute});
factory Response1DocOpeningTimesMondayClosingAt.fromJson(Map map) {
return Response1DocOpeningTimesMondayClosingAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesMondayOpeningAt {
final int hour;
final int minute;
Response1DocOpeningTimesMondayOpeningAt({this.hour, this.minute});
factory Response1DocOpeningTimesMondayOpeningAt.fromJson(Map map) {
return Response1DocOpeningTimesMondayOpeningAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesSaturday {
final Response1DocOpeningTimesSaturdayClosingAt closingAt;
final bool isOpenToday;
final Response1DocOpeningTimesSaturdayOpeningAt openingAt;
Response1DocOpeningTimesSaturday(
{this.closingAt, this.isOpenToday, this.openingAt});
factory Response1DocOpeningTimesSaturday.fromJson(Map map) {
return Response1DocOpeningTimesSaturday(
closingAt: _toObject(
map['closing_at'],
(e) =>
Response1DocOpeningTimesSaturdayClosingAt.fromJson(e as Map)),
isOpenToday: map['is_open_today'] as bool,
openingAt: _toObject(
map['opening_at'],
(e) =>
Response1DocOpeningTimesSaturdayOpeningAt.fromJson(e as Map)));
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['closing_at'] = closingAt?.toJson();
result['is_open_today'] = isOpenToday;
result['opening_at'] = openingAt?.toJson();
return result;
}
}
class Response1DocOpeningTimesSaturdayClosingAt {
final int hour;
final int minute;
Response1DocOpeningTimesSaturdayClosingAt({this.hour, this.minute});
factory Response1DocOpeningTimesSaturdayClosingAt.fromJson(Map map) {
return Response1DocOpeningTimesSaturdayClosingAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesSaturdayOpeningAt {
final int hour;
final int minute;
Response1DocOpeningTimesSaturdayOpeningAt({this.hour, this.minute});
factory Response1DocOpeningTimesSaturdayOpeningAt.fromJson(Map map) {
return Response1DocOpeningTimesSaturdayOpeningAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesSunday {
final Response1DocOpeningTimesSundayClosingAt closingAt;
final bool isOpenToday;
final Response1DocOpeningTimesSundayOpeningAt openingAt;
Response1DocOpeningTimesSunday(
{this.closingAt, this.isOpenToday, this.openingAt});
factory Response1DocOpeningTimesSunday.fromJson(Map map) {
return Response1DocOpeningTimesSunday(
closingAt: _toObject(map['closing_at'],
(e) => Response1DocOpeningTimesSundayClosingAt.fromJson(e as Map)),
isOpenToday: map['is_open_today'] as bool,
openingAt: _toObject(map['opening_at'],
(e) => Response1DocOpeningTimesSundayOpeningAt.fromJson(e as Map)));
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['closing_at'] = closingAt?.toJson();
result['is_open_today'] = isOpenToday;
result['opening_at'] = openingAt?.toJson();
return result;
}
}
class Response1DocOpeningTimesSundayClosingAt {
final int hour;
final int minute;
Response1DocOpeningTimesSundayClosingAt({this.hour, this.minute});
factory Response1DocOpeningTimesSundayClosingAt.fromJson(Map map) {
return Response1DocOpeningTimesSundayClosingAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesSundayOpeningAt {
final int hour;
final int minute;
Response1DocOpeningTimesSundayOpeningAt({this.hour, this.minute});
factory Response1DocOpeningTimesSundayOpeningAt.fromJson(Map map) {
return Response1DocOpeningTimesSundayOpeningAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesThursday {
final Response1DocOpeningTimesThursdayClosingAt closingAt;
final bool isOpenToday;
final Response1DocOpeningTimesThursdayOpeningAt openingAt;
Response1DocOpeningTimesThursday(
{this.closingAt, this.isOpenToday, this.openingAt});
factory Response1DocOpeningTimesThursday.fromJson(Map map) {
return Response1DocOpeningTimesThursday(
closingAt: _toObject(
map['closing_at'],
(e) =>
Response1DocOpeningTimesThursdayClosingAt.fromJson(e as Map)),
isOpenToday: map['is_open_today'] as bool,
openingAt: _toObject(
map['opening_at'],
(e) =>
Response1DocOpeningTimesThursdayOpeningAt.fromJson(e as Map)));
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['closing_at'] = closingAt?.toJson();
result['is_open_today'] = isOpenToday;
result['opening_at'] = openingAt?.toJson();
return result;
}
}
class Response1DocOpeningTimesThursdayClosingAt {
final int hour;
final int minute;
Response1DocOpeningTimesThursdayClosingAt({this.hour, this.minute});
factory Response1DocOpeningTimesThursdayClosingAt.fromJson(Map map) {
return Response1DocOpeningTimesThursdayClosingAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesThursdayOpeningAt {
final int hour;
final int minute;
Response1DocOpeningTimesThursdayOpeningAt({this.hour, this.minute});
factory Response1DocOpeningTimesThursdayOpeningAt.fromJson(Map map) {
return Response1DocOpeningTimesThursdayOpeningAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesTuesday {
final Response1DocOpeningTimesTuesdayClosingAt closingAt;
final bool isOpenToday;
final Response1DocOpeningTimesTuesdayOpeningAt openingAt;
Response1DocOpeningTimesTuesday(
{this.closingAt, this.isOpenToday, this.openingAt});
factory Response1DocOpeningTimesTuesday.fromJson(Map map) {
return Response1DocOpeningTimesTuesday(
closingAt: _toObject(map['closing_at'],
(e) => Response1DocOpeningTimesTuesdayClosingAt.fromJson(e as Map)),
isOpenToday: map['is_open_today'] as bool,
openingAt: _toObject(
map['opening_at'],
(e) =>
Response1DocOpeningTimesTuesdayOpeningAt.fromJson(e as Map)));
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['closing_at'] = closingAt?.toJson();
result['is_open_today'] = isOpenToday;
result['opening_at'] = openingAt?.toJson();
return result;
}
}
class Response1DocOpeningTimesTuesdayClosingAt {
final int hour;
final int minute;
Response1DocOpeningTimesTuesdayClosingAt({this.hour, this.minute});
factory Response1DocOpeningTimesTuesdayClosingAt.fromJson(Map map) {
return Response1DocOpeningTimesTuesdayClosingAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesTuesdayOpeningAt {
final int hour;
final int minute;
Response1DocOpeningTimesTuesdayOpeningAt({this.hour, this.minute});
factory Response1DocOpeningTimesTuesdayOpeningAt.fromJson(Map map) {
return Response1DocOpeningTimesTuesdayOpeningAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesWednesday {
final Response1DocOpeningTimesWednesdayClosingAt closingAt;
final bool isOpenToday;
final Response1DocOpeningTimesWednesdayOpeningAt openingAt;
Response1DocOpeningTimesWednesday(
{this.closingAt, this.isOpenToday, this.openingAt});
factory Response1DocOpeningTimesWednesday.fromJson(Map map) {
return Response1DocOpeningTimesWednesday(
closingAt: _toObject(
map['closing_at'],
(e) =>
Response1DocOpeningTimesWednesdayClosingAt.fromJson(e as Map)),
isOpenToday: map['is_open_today'] as bool,
openingAt: _toObject(
map['opening_at'],
(e) =>
Response1DocOpeningTimesWednesdayOpeningAt.fromJson(e as Map)));
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['closing_at'] = closingAt?.toJson();
result['is_open_today'] = isOpenToday;
result['opening_at'] = openingAt?.toJson();
return result;
}
}
class Response1DocOpeningTimesWednesdayClosingAt {
final int hour;
final int minute;
Response1DocOpeningTimesWednesdayClosingAt({this.hour, this.minute});
factory Response1DocOpeningTimesWednesdayClosingAt.fromJson(Map map) {
return Response1DocOpeningTimesWednesdayClosingAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocOpeningTimesWednesdayOpeningAt {
final int hour;
final int minute;
Response1DocOpeningTimesWednesdayOpeningAt({this.hour, this.minute});
factory Response1DocOpeningTimesWednesdayOpeningAt.fromJson(Map map) {
return Response1DocOpeningTimesWednesdayOpeningAt(
hour: map['hour'] as int, minute: map['minute'] as int);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['hour'] = hour;
result['minute'] = minute;
return result;
}
}
class Response1DocTermsAndConditions {
final String detailed;
final String minimumSpend;
Response1DocTermsAndConditions({this.detailed, this.minimumSpend});
factory Response1DocTermsAndConditions.fromJson(Map map) {
return Response1DocTermsAndConditions(
detailed: map['detailed'] as String,
minimumSpend: map['minimum_spend'] as String);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['detailed'] = detailed;
result['minimum_spend'] = minimumSpend;
return result;
}
}
class Response1OpeningDetails {
final String opensAt;
final bool isNowOpen;
final bool isOpenToday;
final String id;
Response1OpeningDetails(
{this.opensAt, this.isNowOpen, this.isOpenToday, this.id});
factory Response1OpeningDetails.fromJson(Map map) {
return Response1OpeningDetails(
opensAt: map['opensAt'] as String,
isNowOpen: map['isNowOpen'] as bool,
isOpenToday: map['isOpenToday'] as bool,
id: map['id'] as String);
}
Map<String, dynamic> toJson() {
var result = <String, dynamic>{};
result['opensAt'] = opensAt;
result['isNowOpen'] = isNowOpen;
result['isOpenToday'] = isOpenToday;
result['id'] = id;
return result;
}
}
String _fromDateTime(dynamic data) {
if (data == null) {
return null;
}
if (data is DateTime) {
return data.toIso8601String();
}
return data as String;
}
List _fromList(dynamic data, dynamic Function(dynamic) toJson) {
if (data == null) {
return null;
}
var result = [];
for (var element in data) {
var value;
if (element != null) {
value = toJson(element);
}
result.add(value);
}
return result;
}
DateTime _toDateTime(dynamic data) {
if (data == null) {
return null;
}
if (data is String) {
return DateTime.parse(data);
}
return data as DateTime;
}
double _toDouble(dynamic data) {
if (data == null) {
return null;
}
if (data is int) {
return data.toDouble();
}
return data as double;
}
List<T> _toList<T>(dynamic data, T Function(dynamic) fromJson) {
if (data == null) {
return null;
}
var result = <T>[];
for (var element in data) {
T value;
if (element != null) {
value = fromJson(element);
}
result.add(value);
}
return result;
}
T _toObject<T>(dynamic data, T Function(dynamic) fromJson) {
if (data == null) {
return null;
}
return fromJson(data);
}