2017-11-28 19 views
-2

cliendIdとclientSecretを2つの異なるStringに取り込みたいとします。org.json.simple.JSONObjectはjava.lang.Stringにキャストできません

私は、文字列にresponseEntityを取得し、再度それを解析する

String responseEntity = secretRequestMap.get("responseEntity").toString(); 

をやろうとしているJSONパーサーを使用して、それが「メイン」スレッドで例外をスローしています:

java.lang.ClassCastException: org.json.simple.JSONObject cannot be cast to java.lang.String. 

私が調べると、エラーは表示されませんが、実行すると例外がスローされます。助けてください。

String response = {"statusCode":"200","responseEntity":{"clientId":"abc","clientSecret":"xyz"},"errorList":[]}; 
Map<String, String> responseMap = (Map<String, String>) new JSONParser().parse(response); 
+0

'toString'は' JSONObject'のメソッドなのでどこに表示されますか? –

+0

@HotLicks 'toString()'はすべての 'Object'のメソッドです –

+0

実行時例外を取得できません...' String response = {"statusCode": "200" 'コンパイルしません... –

答えて

0

(String)をオブジェクトとして返すため、キャストします。

String responseEntity =(String) secretRequestMap.get("responseEntity").toString(); 
関連する問題