Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

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}
Source by bezkoder.com #
 
PREVIOUS NEXT
Tagged: #dart #list #objects #json
ADD COMMENT
Topic
Name
6+3 =