-2

I want to retrieve cliendId and clientSecret into 2 different Strings.

I am trying to do

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

to get the responseEntity into a string and then parse it again, using JSON parser, but it throws an exception in thread "main":

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

When I inspect it doesn't show any error but when I run it throws exception. Please help.

String response = {"statusCode":"200","responseEntity":{"clientId":"abc","clientSecret":"xyz"},"errorList":[]};
Map<String, String> responseMap  = (Map<String, String>) new JSONParser().parse(response);
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
JavaPassion
  • 75
  • 1
  • 3
  • 9

1 Answers1

2

cast it by using (String) because it will return as an Object.

String responseEntity =(String) secretRequestMap.get("responseEntity").toString(); 
Kalaiselvan
  • 2,095
  • 1
  • 18
  • 31