且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java的解析JSON字节数组

更新时间:2023-01-17 18:50:14

下面是分析这个数组字节[] 使用不可替代的 GSON库

Here is an example of parsing this array to byte[] using the irreplaceable GSON library:

String str = "[255,12,87,183,232,34,64,121,182,23]";
Gson gson = new Gson();
byte[] parsed = gson.fromJson(str, byte[].class);
for (byte b : parsed) {
    System.out.println(b);
}

这code输出:

-1
12
87
-73
-24
34
64
121
-74
23

需要注意的是java的字节签订这样的话你得到负数。

Note that the java byte is signed and thus you get the negative numbers.