Flutter 中文乱码

base64乱码
将base64过的字符串还原成原始文本,String.fromCharCodes会乱码,convert.utf8.decode才不会乱码

/*
  * Base64解密
  */
  static String base64Decode(String data){
    List<int> bytes = convert.base64Decode(data);
    // 网上找的很多都是String.fromCharCodes,这个中文会乱码
    //String txt1 = String.fromCharCodes(bytes);
    String result = convert.utf8.decode(bytes);
    return result;
  }

 

Uint8Buffer转成中文乱码问题,StringBuffer会乱码,Utf8Decoder().convert不会乱码

import 'dart:convert';
static String bytesToStringAsString(typed.Uint8Buffer message) {
// 这个会乱码  
  //final StringBuffer sb = StringBuffer();
  //  message.forEach(sb.writeCharCode);
 //   return sb.toString();

// 不会乱码
String messageTxt = Utf8Decoder().convert(message);
return messageTxt;
  }

转载:https://www.jianshu.com/p/bb824acf408d

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值