<ToJson>
01_id: 0, 02_cityName: 서울
[{build_cost: 22, sell_cost: 11, buildingName: 땅, buy_cost: 44, toll_cost: 8},
{sell_cost: 4, build_cost: 8, buildingName: 빌라, buy_cost: 16, toll_cost: 16},
{build_cost: 24, sell_cost: 12, buildingName: 빌딩, buy_cost: 48, toll_cost: 34},
{sell_cost: 20, build_cost: 40, buildingName: 호텔, buy_cost: 80, toll_cost: 70},
{build_cost: 40, sell_cost: 20, buildingName: 랜드마크, buy_cost: 0, toll_cost: 60}]
class Todo {
final int userId;
final int id;
final String title;
Todo(this.userId, this.id, this.title);
factory Todo.fromJson(
Map<String, dynamic> json,
) {
return Todo(
json['userID'] as int,
json['id'] as int,
json['title'] as String
);
}
Map<String, dynamic> toJson(Todo instance) =>
<String, dynamic> {
'userId': instance.userID,
'id': instance.id,
'title': instance.title
};
}
위 코드는 json_serializable 패키지(JSON 직렬화)를 이용해 자동 생성이 가능하다.
'Flutter' 카테고리의 다른 글
Flutter - 주요 단축기/배너제거/플랫폼구분 (0) | 2022.02.06 |
---|---|
Flutter - File IO / Delay / 가로모드 (0) | 2022.02.06 |
Flutter - Database (0) | 2022.02.06 |
Flutter App Bar/화면크기조절/화면전환 (0) | 2022.02.06 |
Flutter 앱 구조/Widget/Singleton (0) | 2022.02.06 |