Files
sdk/pkg/json/example/main.dart
T
Michael Thomsen 58d8ea21e6 Add json example and edit a few doc comments
Change-Id: Ib297cdb8c2a52d7a9be7f0f3f87a6ea205f99bf4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366140
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Michael Thomsen <mit@google.com>
2024-05-13 14:52:23 +00:00

20 lines
358 B
Dart

import 'package:json/json.dart';
@JsonCodable()
class Point {
int x = 0, y = 0;
}
@JsonCodable()
class ColoredPoint extends Point {
String color = '';
}
main() {
final json = {'x': 12, 'y': 42, 'color': '#2acaea'};
var p = ColoredPoint.fromJson(json);
p.x = 100;
print('JSON ${p.toJson()}'); // Prints: JSON {x: 100, y: 42, color: #2acaea}
}