2017-01-23 21 views
1

私は、コードのコンパイルにhackerrank.com APIを使用しています。ユーザーは、コンパイルエラーでコードを入力するときにJSONレスポンスは、このJSON「compilemessage」では、この特殊文字を含む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 
    } 
} 

のようなものです'' "" ;などのような特別なエスケープ文字が含まれているので、文字がそのまま残るように、この文字列を解析する方法について説明します。

私は通常

jsonobject.getString( "compilemessage")

と解析しようとした場合の画像で

enter image description hereに示すように、それはいくつかのランダムな文字に変換します

+1

[mcve]を含めてください。 – shmosel

+1

前にこのquuestionを参照してくださいhttp://stackoverflow.com/questions/9069799/android-json-charset-utf-8-problems –

+0

解析するために使用しているAPIはどれですか? –

答えて

0

""またはすべての特殊文字にUnicodeを使用するか、/を使用して "すべての文字に/を使用することができます。 またはhakのタックヘルプ How to define special characters in string array java

+0

空間文字がどこにあるのかwhith文字列を追加する必要があります –

+0

しかし、私はそれを解析しているときに文字列エスケープ文字をランダムな文字に変換していますので、サードパーティAPIを使用していますので、 –

関連する問題