1
如何将多个元素放入byte[]
?我有以下3个元素:1)String data
,2)String status
和3)HashMap<String,String> headers
,它们需要作为字节数组传递给setContent(byte[] data)
。下面是我想用以前的3个参数作为输入statusResult.setContent()
代码:如何将多个元素放入java的byte []中
public void onSuccess(ClientResponse clientResponse){
String data=clientResponse.getMessage();
String status=String.valueOf(clientResponse.getStatus());
HashMap<String,String> headers=clientResponse.getHeaders();
// Now StatusResult is a class where we need to pass all this data,having only getters and
// setters for Content,so here in the next line i need to pass data,status and headers as
// a byte[] to setContent.
statusResult.setContent(byte[]);
}
有人可以帮我解决了这一点?
什么,你希望把'data'元素呢?目前还不清楚.. – Maroun
@ᴍarounᴍaroun我把从响应收到的字符串消息放入数据中,它将作为“hello world”的小行。 –
您需要在将对象放入字节[]之前序列化对象。您是否真的知道在将这些字节作为序列化数据传递给该对象之后会发生什么?该对象是否会以适当的方式解释它们? – Ricardo