我使用这个拓扑模型来解析 Json 数据。接收汉字时数据出现乱码。
我曾尝试添加 utf8.decode 之类的
List<Client> clientFromJson(String str) => List<Client>.from(json.decode(utf8.decode(str)).map((x) => Client.fromJson(x)));
Run Code Online (Sandbox Code Playgroud)
但是 IDE 告诉我“无法将参数类型 'String' 分配给参数类型 'List< int >'”。
我应该怎么做才能在模型中添加 utf8 解码器?
///topology.dart
// To parse this JSON data, do
//
// final client = clientFromJson(jsonString);
// final topology = topologyFromJson(jsonString);
import 'dart:convert';
List<Client> clientFromJson(String str) => List<Client>.from(json.decode(str).map((x) => Client.fromJson(x)));
String clientToJson(List<Client> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
List<Topology> topologyFromJson(String str) => List<Topology>.from(json.decode(str).map((x) => Topology.fromJson(x)));
String topologyToJson(List<Topology> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class Topology {
String location;
String mode; …Run Code Online (Sandbox Code Playgroud)