我想阅读下面的XML内容,我正在使用JAXB解析器进行转换 XML对象。 XML doc是UTF-8格式,包含一些utf-8 我没有通过我的对象,但得到的字符??? 代替。
XML文件数据:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CallDetails>
<APPOINTMENTDATE>29.11.2016</APPOINTMENTDATE>
<APPOINTMENTTIME>29.11.2016 11:11:00</APPOINTMENTTIME>
<ASCCODE>83000220</ASCCODE>
<CALLDESC>작동불</CALLDESC>
<CALLRECEIVEDBY>김정권</CALLRECEIVEDBY>
<CALLRECEIVEDMODECODE></CALLRECEIVEDMODECODE>
<CALLREGBYCAT></CALLREGBYCAT>
<CALLREGBYCODE></CALLREGBYCODE>
<CALLREGDATE>29.11.2016</CALLREGDATE>
<CALLREGTIME>29.11.2016 09:11:00</CALLREGTIME>
<CALLTYPECODE>SVC</CALLTYPECODE>
<COVERAGETYPECODE>UW</COVERAGETYPECODE>
<SPECIALREQUEST></SPECIALREQUEST>
</CallDetails>
阅读文件如下,
InputStream inputStream = null;
inputStream = new FileInputStream(path);
InputStreamReader reader = new InputStreamReader(inputStream,"UTF-8");
JAXBContext context = JAXBContext.newInstance(clazz);
Unmarshaller um = context.createUnmarshaller();
InputSource is = new InputSource(reader);
is.setEncoding("UTF-8");
return um.unmarshal(is);
获取对象如下:
THIRDPARTYSERVICEORDERNO = serviceOrderListDTO.getServiceOrderList().get(0).getThirdPartyServiceOrderNo();
CALLDESC = ServiceOrderListDTO.getServiceOrderList().get(0).getCallDetailsList().getCallDesc();
System.out.println("THIRDPARTYSERVICEORDERNO : "+THIRDPARTYSERVICEORDERNO);
System.out.println("CALLDESC: "+CALLDESC);
运行此代码后,我得到如下输出,
THIRDPARTYSERVICEORDERNO : AJ16110004904;
CALLDESC: ???;
答案 0 :(得分:0)
我已对您的代码进行了测试。 它产生的结果是正确的,这意味着在调试模式下,内存中的值显示正确。 将这些符号打印到控制台时,您会看到???因为控制台窗口默认不能显示那些符号。 你必须确定: