Skip to content

Instantly share code, notes, and snippets.

@PlugFox
Created June 17, 2019 13:14
Show Gist options
  • Save PlugFox/2a369ae54afdab0b4464bc4a5e2a1ae6 to your computer and use it in GitHub Desktop.
Save PlugFox/2a369ae54afdab0b4464bc4a5e2a1ae6 to your computer and use it in GitHub Desktop.
json example mapping for https://t.me/rudart
/* json example mapping for https://t.me/rudart */
import "dart:math";
import "dart:convert";
void main() {
String raw = '''
{"rooms": [
{
"id": "49",
"name": "Sonata Room 2",
"rules": "No rules",
"size": 15,
"capacity": 12,
"cancellationPolicy": 24,
"rating": 0,
"images": [],
"instruments": [
{
"id": "99",
"manufacturer": null,
"instrumentModel": null,
"productionYear": null,
"instrument": {
"name": "Cello"
},
"room": {
"id": "49"
}
}
],
"schedule": [
{
"id": "802",
"roomId": 49,
"price": 0,
"priceCurrency": "EUR",
"priceLoc": 0,
"priceLocCurrency": "EUR"
}
]
}
]}
''';
Map<String, dynamic> data = json.decode(raw);
List<Map<String, dynamic>> list = data['rooms'].toList().cast<Map<String, dynamic>>();
print(
list.map<int>((room) => room["size"])
.toList()
.reduce(max)
); // 15
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment