0

I have some JSON text from an API that will always come in this format.

{
    "query": {
        "codes": [
            "94016"
        ],
        "country": "US"
    },
    "results": {
        "94016": [
            {
                "postal_code": "94016",
                "country_code": "US",
                "latitude": "37.70580000",
                "longitude": "-122.46190000",
                "city": "Daly City",
                "state": "California",
                "city_en": "Daly City",
                "state_en": "California",
                "state_code": "CA",
                "province": "San Mateo",
                "province_code": "081"
            }
        ]
    }
}

The above code block shows the output for using 94016 as a zip code. I'm only concerned with the city key and the value associated with it. For this example, the only text I want to return is "Daly City" without the quotes.

I created 2 classes for using Gson later in my project with the following code:

public class ZipcodeResponse {
    ZipcodeResult[] results;
}
    
public class ZipcodeResult {
    String[] ???;
}

My first problem is that I'm not sure what to call my string array (presumably I would name it whatever zip code is searched), since the zipcode will be different each time and the value for it is stored in another class while the program executes. If there's a way I can skip over this value and only get the city, then that would be awesome.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Wes Graham
  • 33
  • 3

0 Answers0