dart convert json string to map code example
Example 1: dart map to json string
import 'dart:convert';
...
json.encode(data); // JSON.encode(data) in Dart 1.x
Example 2: convert json to dart
class Todo {
int userId;
int id;
String title;
bool completed;
Todo({this.userId, this.id, this.title, this.completed});
Todo.fromJson(Map<String, dynamic> json) {
userId = json['userId'];
id = json['id'];
title = json['title'];
completed = json['completed'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['userId'] = this.userId;
data['id'] = this.id;
data['title'] = this.title;
data['completed'] = this.completed;
return data;
}
}