2017-01-23 158 views
1

我正在使用hackerrank.com API進行代碼編譯。因此,當用戶與編譯錯誤代碼進入JSON響應是這樣如何解析包含特殊字符的JSON字符串?

{ 
    "result": { 
    "callback_url": "", 
    "censored_compile_message": "", 
    "codechecker_hash": "something", 
    "compile_command": "/usr/lib/jvm/java-7-sun/bin/javac -encoding UTF-8 -classpath '*:/usr/share/java/json-simple-1.1.1.jar:/usr/share/java/junixsocket.jar:/usr/share/java/abacus-util-jdk7.jar' AddNumbers.java 1> compile.err 2>&1", 
    "compilemessage": "AddNumbers.java:1: error: ';' expected\nimport java.util.Scanner; class AddNumbers { public static void main(String args[]) {  int x, y, z    Scanner in = new Scanner(System.in);  x = in.nextInt();  y = in.nextInt();  z = x + y;  System.out.println(z); } }\n                            ^\n1 error\n", 
    "error_code": 0, 
    "hash": "something", 
    "loopback": null, 
    "memory": null, 
    "message": null, 
    "response_s3_path": "something", 
    "result": 255, 
    "run_command": "", 
    "server": "something", 
    "signal": null, 
    "stderr": null, 
    "stdout": null, 
    "time": null 
    } 
} 

在這個JSON「compilemessage」包含特殊的轉義字符像'' "" ;等。因此,如何使人物保持原樣解析這個字符串。

當我試圖只用正常

jsonobject.getString解析( 「compilemessage」)

然後把它轉換成一些隨機字符作爲圖片所示

enter image description here

+1

請包括[mcve]。 – shmosel

+1

請參閱此quurstion之前http://stackoverflow.com/questions/9069799/android-json-charset-utf-8-problems –

+0

哪一個你用於解析? –

回答

0

使用Unicode代替「」或每個特殊字符,或者您也可以使用/還可以將空格字符用於「你可以使用/爲每個字符 或來自兔子的粘性幫助 How to define special characters in string array java

+0

你必須添加whith字符串,其中是空間字符 –

+0

但是,當我解析它時,只有它將字符串轉義字符轉換爲隨機字符,我使用第三方API,因此不能使用unicode爲「」 –

相關問題