How to access nested elements of JSON data in Java?
<p>I'm getting JSON data from a url and I want to show the data on my website. I am successfully showing all JSON data except JSON Hierarchy (JSON Object) data. I am able to access JSONArray <code>person</code> and <code>error</code> data. But, I am not able to access hierarchy (JSON Object) <code>updated</code> data. </p>

<p>I want to access <code>updated.time</code>. </p>

<pre><code>import java.io.IOException;
import java.net.URL;
import org.apache.commons.io.IOUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;

public class ParseJson1 {

public static void main(String[] args) {
    String url = "http://freemusicarchive.org/api/get/genres.json?api_key=60BLHNQCAOUFPIBZ&amp;limit=2";
    /*
   {
"person": [
    {
        "name": "John",
        "city": "Mumbai"
    },
    {
        "name": "Rahul",
        "city": "Delhi"
    },
    {
        "name": "Sanjana",
        "city": "Amritsar"
    },
    {
        "name": "Anjali",
        "city": "Hyderabad"
    },
    {
        "name": "Mukund",
        "city": "Bangalore"
    },
    {
        "name": "Raunak",
        "city": "Patna"
    }
],
"updated": {
    "time": "14:17:48",
    "date": "2016-04-10"
},
"error": "2353"
}

 */

    try {
        String genreJson = IOUtils.toString(new URL(url));
        JSONObject genreJsonObject = (JSONObject) JSONValue.parseWithException(genreJson);
        // get the error
        System.out.println(genreJsonObject.get("error"));

        //Get Array Values
        JSONArray genreArray = (JSONArray) genreJsonObject.get("person");
        // get the first genre
        JSONObject firstGenre = (JSONObject) genreArray.get(0);
        System.out.println(firstGenre.get("name"));
        // get the Second
        JSONObject firstGenre = (JSONObject) genreArray.get(1);
        System.out.println(firstGenre.get("name"));
        // get the third
        JSONObject firstGenre = (JSONObject) genreArray.get(2);
        System.out.println(firstGenre.get("city"));


    } catch (IOException | ParseException e) {
        e.printStackTrace();
    }
}
}
</code></pre>