[英]JAXB unmarshalling Unknown issue
我正在使用JAXB解組xml,但是突然返回錯誤的值。 前一天工作正常。
節點: <ListID>166</ListID>
解組代碼為:
public class ResponseParser {
static Object obj;
public static Object parseResponse(String response, Class<?> ctxClass) {
try {
ByteArrayInputStream input = new ByteArrayInputStream(response.getBytes());
JAXBContext jc = JAXBContext.newInstance (ctxClass);
Unmarshaller unmarshaller = jc.createUnmarshaller();
obj = unmarshaller.unmarshal(input);
}
catch (JAXBException e) {
}
return obj;
}
}
它返回: -90
。但是它像-90
之前一樣順序返回-91
請幫忙!
輸入166
超出了byte
的范圍,在Java中最大值為127
。
package forum9632269;
public class Demo {
public static void main(String[] args) throws Exception {
System.out.println(Byte.MAX_VALUE);
}
}
輸出量
127
您面對的事情很奇怪,但也許與xml文件編碼有關。 嘗試更換電話
ByteArrayInputStream input = new ByteArrayInputStream(response.getBytes());
至
ByteArrayInputStream input = new ByteArrayInputStream(response.getBytes("UTF8"));
讓我們知道這是否是您遇到問題的真正原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.