我正在尝试打印以控制台我的 java bean,从 HTTP 响应中解组。我有编码问题。以下是部分回复:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Response>
<ErrorMsg>Ä°ÅŸleminizi ...</ErrorMsg>
</Response>
我的方法是:
public void printToConsole() {
try {
JAXBContext context = JAXBContext.newInstance(Response.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.marshal(this, System.out);
} catch (JAXBException e) {
e.printStackTrace();
}
}
通过使用调试器查看 bean 值,它们会在调试器的弹出窗口中正确显示(Eclipse IDE)
谢谢