So in my app I have to get a JSON string. It can be a City or a List of Cities.
In the City class I have this:
public class City
{
public string id { get; set; }
public string country { get; set; }
public string region { get; set; }
public string city { get; set; }
public string latitude { get; set; }
public string longitude { get; set; }
public string comment { get; set; }
public bool wasThereAnError { get; set; }
public class CityResponse
{
public string status { get; set; }
public string message { get; set; }
//public City result { get; set; }
public List<City> result { get; set; }
}
So it uses the List result to store data. This works fine when I get a JSON array back, it stores them all easily. However if I just query for 1 city, I get an exception about it needing an array. Here is the code for my call:
async private Task<City.CityResponse> GetCityInformation(string url)
{
var client = new HttpClient();
var response = await client.GetAsync(new Uri(url));
string result = await response.Content.ReadAsStringAsync();
var cityRoot = JsonConvert.DeserializeObject<City.CityResponse>(result);
return cityRoot;
}
Is it possible for me to store 1 city in the list too? Or do I need to make a seperate cities class or how do I go about this? Thanks