[英]How to parse JSON String containing special characters?
我正在使用hackerrank.com API進行代碼編譯。 因此,當用戶輸入帶有編譯錯誤的代碼時,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”)
然后它將其轉換為一些隨機字符,如圖所示
使用Unicode代替“”或者代表每個特殊字符,或者你也可以使用/也代表空間字符“你可以使用/代表每個字符或者來自野兔的幫助如何在字符串數組java中定義特殊字符
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.