2011-06-21 15 views
0

JSON請願書HTTPで受け取りました。 Internet Explorer 8解析から来る場合は例外で失敗:制御文字を使用したJava問題のJSON構文解析

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にのみ影響するようです。

ありがとうございます。

答えて

0

誰もが同じ問題に陥った場合に備えて、私はこの質問を削除しません。

問題は、実行時にXMLに変換した後にC:\fakepath\のようなパスを送信するブラウザで、\fという状態です。

ブラウザでこの動作を設定できます。

よろしくお願いいたします。