79607647

Date: 2025-05-05 21:20:36
Score: 0.5
Natty:
Report link

I agree with David Newcomb, just make it simple and extract the relevant informations which then you can redirect where it is required. The issue you are having is from trying to treat an array (weather) as a map. Instead of doing that, it's much easier and safer to let Gson handle it like in this simple example:

URL url = new URL(REQUEST_URL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
Scanner scanner = new Scanner(con.getInputStream());
StringBuilder output = new StringBuilder();

while (scanner.hasNextLine()) {
    output.append(scanner.nextLine());
}

scanner.close();
con.disconnect();

Gson gson = new Gson();
Root root = gson.fromJson(output.toString(), Root.class);

// Example usage:
City city = root.city; // Replace with actual fields as per your model
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Gutara Balakrishnan