[Solved] Why am I getting this error ?? java.lang.ClasscastException


The top level object in your JSON file is an array so:

class letsRead 
 {
    public static void main(String [] args)
    {
        String inline = "";
    
        try
        {
            URL url = new URL("https://gist.githubusercontent.com/anubhavshrimal/75f6183458db8c453306f93521e93d37/raw/f77e7598a8503f1f70528ae1cbf9f66755698a16/CountryCodes.json");
                    
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    
            conn.setRequestMethod("GET");
            
            conn.connect();
            
            int responsecode = conn.getResponseCode();
            System.out.println("Response code is: " +responsecode);
            
            if(responsecode != 200)
                throw new RuntimeException("HttpResponseCode: " +responsecode);
            else
            {
                Scanner sc = new Scanner(url.openStream());
                while(sc.hasNext())
                {
                    inline=inline + sc.nextLine();
                }
                System.out.println("\nJSON Response in String format"); 
                System.out.println(inline);
                sc.close();
            }
           
            JSONParser parse = new JSONParser();
                       
            JSONArray jsonarr_1 = (JSONArray)parse.parse(inline);
        
            for(int i=0;i<jsonarr_1.size();i++)
            {
                
                JSONObject jsonobj_1 = (JSONObject)jsonarr_1.get(i);
                System.out.println(jsonobj_1.get("name"));
                
                
            }
                    conn.disconnect();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
 }

0

solved Why am I getting this error ?? java.lang.ClasscastException