0
我通過HTTP
接收JSON請願書。當從Internet Explorer 8
解析未來失敗例外:JSON解析JAVA問題與控制字符
InPart inPart = mp.next();
MyClass myClass = inPart.getBody(MyClass.class, null);
com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character ((CTRL-CHAR, code 12)) at [row,col {unknown-source}]: [1,101]]
相關的代碼:
InPart inPart = mp.next();
String s = inPart.getBody(String.class, null);
providers.getMessageBodyReader(MyClass.class, null, null,
MediaType.APPLICATION_JSON_TYPE).readFrom(MyClass.class, null, null,
MediaType.APPLICATION_JSON_TYPE, headers.getRequestHeaders(),
new ByteArrayInputStream(s.getBytes())); // Tried with s.getBytes("UTF-8")
com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character ((CTRL-CHAR, code 12)) at [row,col {unknown-source}]: [1,101]
而且,如果我做的:
String ss = s.replaceAll("\\p{Cntrl}", "");
ss.equals(s); //
輸出真正的
長度是相同。
我也試過:
private String removeControlChar(String in) {
StringBuilder sb = new StringBuilder();
for (char c : in.toCharArray())
{
if(!Character.isISOControl(c)) {
sb.append(c);
}
else
{
// To delete
int i = 0;
}
}
return sb.toString();
}
InPart inPart = mp.next();
String s = inPart.getBody(String.class, null);
Strign ss = removeControlChar(s);
providers.getMessageBodyReader(MyClass.class, null, null,
MediaType.APPLICATION_JSON_TYPE).readFrom(MyClass.class, null, null,
MediaType.APPLICATION_JSON_TYPE, headers.getRequestHeaders(),
new ByteArrayInputStream(ss.getBytes())); // Tried with s.getBytes("UTF-8")
如果我調試,從而未能字符是\f
作爲例外規定。但是錯誤表明它是一個無效的XML字符。這可能是問題嗎?
任何想法?這似乎隻影響Internet Explorer。
謝謝。