Chapter 17 — JSON and Data Modeling
Part 1A — Learning Dart · Chapter 17 of 62 · 6 h
Chapter 17 — JSON and Data Modeling
Level: intermediate Estimated time: 6 h Prerequisites: Chapter 16 — Organizing a Dart Project (and Chapters 9, 12, 13, 14) What you'll be able to do by the end: turn JSON text into typed Dart objects and your Dart objects into JSON text, while cleanly handling missing values, inconsistent types, and format errors.
17.0 — Chapter Objectives
By the end of this chapter, you will be able to:
- explain what JSON is for and why everyone uses it;
- recognize the six JSON value types;
- read and write a JSON object and a JSON array;
- list the differences between JSON and a Dart
Map; - follow JSON syntax rules (double quotes, no trailing comma);
- decode text with
jsonDecode()and encode withjsonEncode(); - explain why
jsonDecode()returnsdynamic; - cast a result to
Map<String, dynamic>andList<dynamic>; - write a model class with
fromJson()andtoJson(); - do an object → JSON → object round trip with no loss;
- handle nested objects and lists of nested objects;
- write defensive code to deal with missing values and inconsistent types;
- catch a
FormatExceptionon invalid JSON; - convert
enums andDateTimes to JSON and back; - save and reload a game session in a JSON file;
- understand what
json_serializableis for; - connect all this to the REST APIs you will consume in Flutter.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion