0

我有一个字节数组,JSON我想恢复它。

Java 代码

String client = ui.ReturnJSon();            
ArrayList<JSONObject> vetor = ArrayJson(client);                    
JOptionPane.showMessageDialog(ui, vetor.size()); // print 56 (that's right)                     
int client_Id = vetor.get(0).get("Cliente_Id");
JOptionPane.showMessageDialog(ui, client_Id); // print 1414509 (that's right)

byte[] template = (byte[])vetor.get(0).get("template");
JOptionPane.showMessageDialog(ui, template.length); // Doesn't appear any Dialog

如何从我的 JSON 中获取字节数组?

模型层

public class lb
{
    public byte[] template { set; get; }
    public byte[] template2 { set; get; }
    public byte[] template3 { set; get; }
    public int Client_Id { set; get; }
}

JSON 示例

    [{"template":[167,255,1,30,17,1,204,0,1,237,0,128,0],
"template2":[167,255,1,30,17,1,204,0,1,237,0,128,0,171,0,1,31],
"template3":null,
"Cliente_Id":1414509},
4

1 回答 1

0

叹!

List template = vetor.get(0).get("template");
byte[] byteArray = new byte[template.size];
For (int i = 0; i < template.size; i++) {
    byteArray[i] = template.get(i).byteValue();
}
于 2013-10-28T18:05:34.050 回答