Run ❯
Get your
own
website
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Change Language
Go to Spaces
Ctrl+Alt+P
import 'dart:convert'; class Book { final String title; final int pages; Book(this.title, this.pages); factory Book.fromJson(Map
json) { return Book(json['title'] as String, json['pages'] as int); } Map
toJson() { return {'title': title, 'pages': pages}; } } void main() { Book book = Book.fromJson(jsonDecode('{"title": "Dune", "pages": 412}')); print('${book.title} has ${book.pages} pages'); Book newBook = Book('Emma', 474); print(jsonEncode(newBook.toJson())); }
Dune has 412 pages
{"title":"Emma","pages":474}