各位大侠好,App与服务器通过byte数组的形式来传输某个类,App这边接收的时候执行byte数组转Object时总是报错:java.io.StreamCorruptedException,下面是异常信息:
V/ObjDebug: ??��sr��com.wanshang.po.Users����������������I��idF��pointL��namet��Ljava/lang/String;L��passwordq��~��L��paypasswordq��~��L��phoneq��~��L��usertypeq��~��xp������E?v��t��jatt��123456t��*t��18819257754t��customer
W/System.err: java.io.StreamCorruptedException
W/System.err: at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2067)
W/System.err: at java.io.ObjectInputStream.<init>(ObjectInputStream.java:372)
W/System.err: at com.wanshang.wanshangapplication.tools.DataTools.byteToObj(DataTools.java:59)
W/System.err: at com.wanshang.wanshangapplication.tools.HttpUtils.dealResponseResult(HttpUtils.java:104)
W/System.err: at com.wanshang.wanshangapplication.tools.HttpUtils.postData(HttpUtils.java:51)
W/System.err: at com.wanshang.wanshangapplication.ui.MainActivity$6.run(MainActivity.java:195)
W/System.err: at java.lang.Thread.run(Thread.java:841)
乱码部分是byte数组的输出,可以看到有类的属性名,就是转换成Object的时候出问题,下面是转换代码:
//数组转对象
public Object byteToObj (byte[] bytes) {
Object obj = null;
try {
ByteArrayInputStream bis = new ByteArrayInputStream (bytes);
ObjectInputStream ois = new ObjectInputStream (bis);
obj = ois.readObject();
ois.close();
bis.close();
} catch (Exception e) {
e.printStackTrace();
}
return obj;
}
请问这个问题该如何解决?