首页 > 解决方案 > 如何在 Android 中将字节字符串转换为 Ascii 字符串

问题描述

我一直在试图找到一种简单的方法来将我从第三方软件获得的缓冲区值转换为将以 .json 格式保存的 ascii 字符串,我不想要原始的十六进制格式。有什么建议么?

这是缓冲区内容的示例:

5B 7B 22 54 65 73 74 49 6E 50 72 6F 67 72 65 
73 73 22 3A 20 22 4E 6F 22 2C 20 22 41 70 70 
6C 69 63 61 74 69 6F 6E 20 53 6F 66 74 77 61 
72 65 20 54

我要这个:

[{"TestInProgress": "No", "Application Software T

我的代码:

// Dynamically size the buffer according to file size
Buffer buff = new Buffer(Integer.valueOf(String.valueOf(FileSize)));//5000);

// read DATASIZE from the begginig of the file
jNQfile.read(buff);
Log.i(TAG, "IN AsyncTask in after read in jNQ the path ---------------------------->:" + DirForjNQ );   // debug msg

// Still in this format Message =  Buffer: [5B 7B 22 54 65 ....] 
String Message = buff.toString();

该文件从服务器复制,第三方堆栈设置并处理 smb。它被复制到他们的缓冲区中。该文件已经是 .json 格式。我只想要 ASCII 字符,而不是十六进制表示。

标签: javaandroidjson

解决方案


推荐阅读