import 'dart:convert'; class ImMessage { final String type; final String from; final String to; final String content; ImMessage({ required this.type, required this.from, required this.to, required this.content, }); factory ImMessage.fromJsonString(String json) { return ImMessage.fromJson(jsonDecode(json)); } factory ImMessage.fromJson(Map json) { return ImMessage( type: json['type'], from: json['from'], to: json['to'], content: json['content'], ); } Map toJson() => { 'type': type, 'from': from, 'to': to, 'content': content, }; String toJsonString() { return jsonEncode(toJson()); } }