Diego Alves
Diego Alves

Reputation: 2697

Why can't I instantiate a JSONObject in Java (string cannot be converted to map)

I am reading a Stackoverflow post (here), I am writing the code contained in the answer but I can't instantiate a JSONObject. The post don't specify where JSONObject comes from so imported it as follows:

  import org.json.simple.JSONObject;  

  String jsonData = response.body().string();
  JSONObject json = new JSONObject(jsonData); //jsonData marked as the soruce of the error and the message "incompatible types cannot convert string to map" shows.

Upvotes: 0

Views: 8954

Answers (1)

RobCo
RobCo

Reputation: 6515

You probably want org.json.JSONObject. That one has a constructor that takes a String.

Upvotes: 2

Related Questions