首页 > 解决方案 > 特殊字符在 Firestore 字符串中不起作用

问题描述

我正在尝试将一些数据从网站提取到我的 Firebase Firestore 数据库,但我遇到了一个小问题,即特殊字符被转换为奇怪的字符,例如这句话“他擅长 - 找人”。换算成“他擅长——找人”这个词,我是不是要逃避那些角色还是什么?

代码:

String url =
      'some-url';
  var response = await http.get(url);
  String body = response.body;
  List results = jsonDecode(body)['results'];
 await firestore
            .collection('games')
            .document(results[i]['id'].toString())
            .setData({
          'description': results[i]['description']});

标签: google-cloud-firestore

解决方案


只是使用 utf8 来解码结果字符串,

utf8.decode(results[i]['description'].toString().runes.toList());

感谢帮助。


推荐阅读