小编陳映存*_*陳映存的帖子

如何添加utf8解码器解决flutter http请求乱码问题?

我使用这个拓扑模型来解析 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)

https json utf-8 dart flutter

1
推荐指数
1
解决办法
684
查看次数

标签 统计

dart ×1

flutter ×1

https ×1

json ×1

utf-8 ×1