flutter - FormatException Uint8List 使用 dart 转换为字符串
问题描述
我正在尝试使用 Dart(在 Flutter 项目中)将 Uint8List 转换为字符串。我正在使用 Flutter Android USB 串行插件(https://github.com/altera2015/usbserial)
数据来自 USB 设备,并作为流从库中返回。
如果输出为字符串,它看起来像:
[255,0,0,0,255....]
当我尝试:
String newTag = ascii.decode(asyncSnapshot.data);
我得到错误:
FormatException:Invalid value in input: 255
我不知道如何解决这个问题,我的结果应该是:
"352206000079439"
解决方案
试试这个;
List<int> list = 'someData'.codeUnits;
Uint8List bytes = Uint8List.fromList(list);
String string = String.fromCharCodes(bytes);
推荐阅读
- asp.net-mvc - RouteData 仅在 .NET Core 3 上不适用于 HttpContext
- java - 使用 Java 将 PySpark 提交到 Yarn 集群
- android - 如果 JSONArray 中的 id 相同,如何在一个 textview 上显示值
- android - Flutter 中的卡片轮播
- symfony - Symfony Query Builder:避免转义双引号
- firebase - 我在 Firestore 中有数据,并提交了值,但其中一些显示为 null
- java - 无法生成 DataBindingClass(Impl 确实生成)
- google-cloud-platform - gcloud 函数部署失败,出现 .cloudignore 文件
- r - 如何在 R 的 tidyverse 中有效地嵌套()和 unnest_wider()
- r - 在 rmarkdown 的代码块中插入幻灯片中断