0
{
    "count": 61,
    "next": "https://swapi.co/api/planets/?page=2",
    "previous": null,
    "results": [
        {
            "name": "Alderaan",
            "rotation_period": "24",
        },
        {
            "name": "Yavin IV",
            "rotation_period": "24",
        },

    ]
}

How I can convert to Array? Whe JsonObject Requires Map?

    String responseString=content.toString();
    System.out.println(responseString);
    JSONObject jsonObject = new JSONObject(responseString);

Error: JSONObject request map

Mech
  • 3,952
  • 2
  • 14
  • 25
sapef44489
  • 69
  • 9
  • Which JSON library are you using? In other words from which package you import `JSONObject`? OR what you see when you execute `System.out.println(JSONObject.class.getName());`? – Pshemo Mar 16 '20 at 19:55
  • What you want to do is called deserialization. You probably want to use `ObjectMapper`. It's pretty easy to use. See [this article](https://www.baeldung.com/jackson-object-mapper-tutorial) for some examples. – Christopher Schneider Mar 16 '20 at 19:56
  • 1
    Does this answer your question? [How to parse JSON in Java](https://stackoverflow.com/questions/2591098/how-to-parse-json-in-java) – Dmitry Pisklov Mar 16 '20 at 19:56
  • Library org.json.simple.JSONObject – sapef44489 Mar 16 '20 at 20:01
  • `org.json.simple.JSONObject` doesn't have constructor which accepts String, `org.json.JSONObject` does but that is different library. – Pshemo Mar 16 '20 at 20:04
  • How I can install it? From Marvel? – sapef44489 Mar 16 '20 at 20:07
  • How did you "install" `org.json.simple`? If your project is configured to use Maven or Gradle then just add proper dependency. If not you can always add JAR file manually to your project, you can download JAR from https://github.com/stleary/JSON-java (scroll down to see more info beside project structure). – Pshemo Mar 16 '20 at 20:21

0 Answers0