Cloud Stack Ninja

I need to take the "id" from "wather" part, that come from json file.

I know that i have to take the first element but I don't know how to do it. How i get first element using get method?

A part weatherMap all code works fine!

Help me. Thanks!

Java file

StringBuilder result=new StringBuilder();
                        URL url=new URL(urlString);
                        URLConnection conn= url.openConnection();
                        BufferedReader rd=new BufferedReader(new InputStreamReader(conn.getInputStream()));
                        String line;
                        while((line=rd.readLine())!=null) {
                            result.append(line);
                        }
                        rd.close();

   Map<String , Object>weatherMap=jsonToMap(respMap.get("weather")[0].toString());                      
   System.out.println("ID logo: "+weatherMap.get("icon"));
                

Json file

    {
      "coord": {
        "lon": 12.84,
        "lat": 45.78
      },
      "weather": [
        {
          "id": 800,
          "main": "Clear",
          "description": "clear sky",
          "icon": "01d" // I neeed this
        }
      ],
      "base": "stations",
      "main": {
        "temp": 16.67,
        "feels_like": 16.35,
        "temp_min": 16.11,
        "temp_max": 17.22,
        "pressure": 1019,
        "humidity": 64
      },
      "visibility": 10000,
      "wind": {
        "speed": 0.45,
        "deg": 230,
        "gust": 1.34
      },
      "clouds": {
        "all": 0
      },
      "dt": 1603033884,
      "sys": {
        "type": 3,
        "id": 2003804,
        "country": "IT",
        "sunrise": 1602998965,
        "sunset": 1603037863
      },
      "timezone": 7200,
      "id": 3170086,
      "name": "Portogruaro",
      "cod": 200
    }


Read more here: https://stackoverflow.com/questions/64415438/im-getting-this-error-the-type-of-the-expression-must-be-an-array-type-but-it-r

Content Attribution

This content was originally published by fil_2020 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: