티스토리 뷰
[Flutter] JsonSerialize(encode / decode)
클래스 맴버로 toJson, fromJson 메서드를 만들어 준 후
dart:convert 라이브러리의 jsonEncode, jsonDecode 함수로 변환해준다.
https://api.flutter.dev/flutter/dart-convert/jsonEncode.html
jsonEncode function - dart:convert library - Dart API
jsonEncode function String jsonEncode(Object? object, {Object? toEncodable(Object? nonEncodable )?} ) Converts object to a JSON string. If value contains objects that are not directly encodable to a JSON string (a value that is not a number, boolean, strin
api.flutter.dev
json_serializable 패키지를 사용하는 방법도 있는데 다른 언어(C#, Java, javascript)들 처럼 간편하진 않다.
@JsonSerializable 어노테이션을 선언 한 후 json_serializable 패키지 명령어로 utility code( _$클래스명ToJson, _$클래스명FromJson )를 생성해서 위와 같은 방식으로 toJson, fromJson에 생성된 utiltiy code의 함수를 반환해주는 방식이다.
https://docs.flutter.dev/data-and-backend/serialization/json
JSON and serialization
How to use JSON with Flutter.
docs.flutter.dev
'Programming Framework > Flutter' 카테고리의 다른 글
[Flutter] Splash Screen(앱 시작 화면) 만들기 (0) | 2024.05.26 |
---|---|
[Flutter] GetIt 패키지를 이용한 Service Locator 전역 상태 관리 (0) | 2024.05.25 |
[Flutter] SliverList 고정되는 항목 만들기 (0) | 2024.05.23 |
[Flutter] ListView 오류 Vertical viewport was given unbounded height. (0) | 2024.05.17 |
[Flutter] 우측 상단 'DEBUG' 배너 제거하기 (0) | 2024.05.16 |
- Total
- Today
- Yesterday
- Windows
- high1
- 전자정부
- CentOS
- Java
- MySQL
- eGovFrame
- php
- 이클립스
- express
- Eclipse
- Entity Framework Core
- c#
- egoverment
- Spring
- jQuery
- 하이원
- .NET Core
- 스프링
- MariaDB
- Fedora
- JSP
- Flutter
- dotnet core
- ubuntu
- Linux
- asp.net core
- 자바
- DART
- egov
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |