How do I get the nested key element in a JSON object, using org.json?

Aleksey Budaev :

I need the keys direct and 242. JSON structure:

   "advert": {
      "direct": {
         "url": "//direct.yandex.ru/",
         "params": {
            "add_type": "direct",
            "direct_page_id": 242
         }
      }

I use

jsonObj.getJSONObject("advert").getJSONObject("direct").getJSONObject("params").get("add_type")

but it doesn't seem optimal to me. Is there another way?

Shashank Chandrakar :

You can JACKSON library to convert the above JSONString to POJO class and retrieve the data. You can create a complex POJO class that will contain the above data.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=389170&siteId=1