I am consuming an API which returns the following JSON
{"coord":{"lon":-1.38,"lat":54.91},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"base":"stations","main":{"temp":285.83,"pressure":1013,"humidity":76,"temp_min":285.15,"temp_max":286.15},"visibility":10000,"wind":{"speed":5.1,"deg":240},"clouds":{"all":20},"dt":1536913200,"sys":{"type":1,"id":5104,"message":0.0049,"country":"GB","sunrise":1536903391,"sunset":1536949457},"id":2636531,"name":"Sunderland","cod":200}
I call the API and return the JSON as a string (strJson), from strJson I use the following code to deserialize the JSON and return the values.
JsonResponse res = JsonConvert.DeserializeObject<JsonResponse>(strJson);
I am able to return the items that reside within "weather" by using the following inside my JsonResponse class (I'm only returning "main" at the moment, which works successfully;
class JsonResponse
{
public object coord { get; set; }
public IList<Weather> weather { get; set; }
}
}
class Weather
{
public string main { get; set; }
}
I have tried all sorts to return the data that resides within "coord" and "sys" but i keep getting the error "Cannot deserialize the JSON array (e.g. [1,2,3]) into type ' ' because type requires JSON object (e.g. {“name”:“value”}) to deserialize correctly".
I am able to return into into an "object" using
public object coord {get; set;}
however this isn't effective as I'm still unable to quickly extract the variables lon & Lat as well as their values.
Any help would be appreciated as I've asked a similar question before, however the answers I've found stop me from being able to extract the values from "weather" so I'm stumped.