我正在使用aqueduct web api框架来支持我的Flatter应用程序.在我的api后端,我需要连接本地网络套接字服务.我的问题是,我无法返回准确的字符串(在tr中).So, How can I convert string to utf8 in Dart?
Example:个
@httpGet
Future<Response> getLogin() async {
Socket.connect('192.168.1.22’, 1024).then((socket) async {
socket.listen((data) {
// Expected return is: 1:_:2:_:175997:_:NİYAZİ TOROS
print(new String.fromCharCodes(data).trim());
xResult = new String.fromCharCodes(data).trim();
print("xResult: $xResult");
}, onDone: () {
print("Done");
socket.destroy();
});
socket.write('Q101:_:49785:_:x\r\n');
});
return new Response.ok(xResult);
}
退货不是TR-TR语言格式.
返回文本如下所示:
正确答案必须是:
更新:
-
xResult = new String.fromCharCodes(data).trim();
个 print(xResult);
-
responseBody = xResult.transform(utf8.decoder);
个 -
print(responseBody);
个
我可以打印xResult
,但在try 转换为UTF8后无法打印responseBody