我的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},
答案 0 :(得分: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();
}