1-) FLUTTER - Json dan Objeye veya Objeden Jsona Dönüştürme Json to Object Serializable Class Model
ENCODE | DECODE |
import 'dart:convert';
//diğer String text = jsonEncode(tumbaka);
//diğer2 Iterable l =json.decode(jsonListem!);
|
Map<String, dynamic> map = jsonDecode(json);
|
encode kaynak : https://stackoverflow.com/questions/50129573/dart-json-encode-returns-json-string-with-key-values-without-quotes
| decode kaynak : https://stackoverflow.com/questions/51601519/how-to-decode-json-in-flutter
|
class UrunDetayList {
|
GETX KULLANIRSAN ".VALUE" DİCEKSİN
class UrunDetayList extends GetxController {
|
*************************************** DİĞER ***************************************
terminale yaz çalıştır -> dart pub add json_serializable -> kaynak : https://pub.dev/packages/json_serializable
terminale yaz çalıştır -> dart pub add build_runner --dev -> kaynak : https://pub.dev/packages/json_serializable
terminale yaz çalıştır -> flutter pub get
Açıklama : Sanırım Constructer kullanmak zorunlu
1- sorular.dart
import 'package:json_annotation/json_annotation.dart';
|
2- Ardından bunu çalıştır -> flutter pub run build_runner build
3- Aşağıdaki gibi otomatik dosya oluşturcak
// GENERATED CODE - DO NOT MODIFY BY HAND |
|
4- KULLANIMI
var text = sorularim.toJson().toString();
debugPrint('jsonum: $text ');
model için
Sorular so1 = Sorular.fromJson( jsonDecode(json2));