我正在使用 aqueduct web api 框架来支持我的颤振应用程序。在我的 api 后端,我需要连接本地网络套接字服务。我的问题是我无法返回确切的字符串(在 tr 中)。S o,如何在 Dart 中将字符串转换为 utf8?
例子:
@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 语言格式。
返回文本如下所示: 1: :2: :175997:_:NÝYAZÝ TOROS
正确的必须是: 1: :2: :175997:_:NİYAZİ TOROS
更新:
xResult = new String.fromCharCodes(data).trim();print(xResult);responseBody = xResult.transform(utf8.decoder);print(responseBody);
我可以打印但在尝试转换为 UTF8 后xResult无法打印responseBody
