Search
 
SCRIPT & CODE EXAMPLE
 

DART

dart list to json

import 'dart:convert';

main() {
  List<String> tags = ['tagA', 'tagB', 'tagC'];
  String jsonTags = jsonEncode(tags);
  print(jsonTags);      // ["tagA","tagB","tagC"]
}
Comment

dart list of objects to json

class User {
  String name;
  int age;
  User(this.name, this.age);
  Map toJson() => { // You must create this toJson() method else you will get an error
        'name': name,
        'age': age,
      };
}


//Now in your main fucntion, use jsonEncode
import 'dart:convert';
main() {
  User user = User('Shristi Gautam', 25);
  String jsonUser = jsonEncode(user);
  print(jsonUser);
}

The result will be something like {"name":"Shristi Gautam","age":25}
Comment

PREVIOUS NEXT
Code Example
Dart :: custom error snackbar flutter 
Dart :: how to disable windows build flutter 
Dart :: convert string to float .0 dart 
Dart :: list of strings in dart 
Dart :: replace string in dart,replace string in dart using regex 
Dart :: flutter column vertical direction 
Dart :: final vs const dart 
Dart :: flutter full screen bottom sheet 
Dart :: text field validation in flutter 
Dart :: dart read file 
Dart :: space around in flutter 
Dart :: get direction routes in mapbox flutter 
Dart :: flutter date add time 
Dart :: flutter add value to list<map<string, int 
Dart :: chips in flutter 
Dart :: flutter close bottomsheet programmatically 
Dart :: raisedbutton full width flutter 
Dart :: flutter sliver grid 
Dart :: input in dart 
Dart :: flutter appbar remove padding 
Dart :: flutter: httpclient method 
Dart :: dart input int 
Dart :: change app font flutter 
Dart :: dart key value pair list 
Dart :: how to pass a double value from text field using flutter 
Dart :: what is interface in dart 
Dart :: flutter convert list dynamic to list string 
Dart :: flutter firebase 
Dart :: flutter timeseries chart 
Dart :: widget capture in flutter 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =