asp.net web api - Json deserialize error c# mvc -


controller { namespace webapplication10.controllers {     public class default1controller : apicontroller     {         [responsetype(typeof(weatheritem))]         public weatheritem post(wcall call)         {              string apikey = //myapikey;             string url = string.format("http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&units=metric&cnt=1&appid={1}", call.city1, apikey);             webclient a1 = new webclient();             string dataweather = a1.downloadstring(url);              weatheritem a2 = jsonconvert.deserializeobject<weatheritem>(dataweather);             string przyklad = a2.list.pressure;             return a2;         }     } } } class { namespace webapplication10.models {     public class weatheritem     {         public list list { get; set; }         public string cod { get; set; }         public string message { get; set; }         public int cnt { get; set; }         //public list<city> city { get; set; }            }     public class list     {         public int dt { get; set; }        // public list<temp> temp { get; set; }         public string pressure { get; set; }         public int humidity { get; set; }        // public list<weather> weather { get; set; }         public string speed { get; set; }         public string deg { get; set; }         public string clauds { get; set; }         public int rain { get; set; }     }     public class wcall     {         public string city1 { get; set; }         public string street { get; set; }     }     public class city     {         public int id { get; set; }         public string name { get; set; }         //public list<coords> coords { get; set; }         public string country { get; set; }         public int population { get; set; }     }     public class coords     {         public string lon { get; set; }         public string lat { get; set; }     }     public class temp     {         public string day { get; set; }         public string min { get; set; }         public string max { get; set; }         public string night { get; set; }         public string eve { get; set; }         public string morn { get; set; }     }     public class weather     {         public int id { get; set; }         public string main { get; set; }         public string description { get; set; }         public string icon { get; set; }     } } } 

exception:an exception of type 'newtonsoft.json.jsonserializationexception' occurred in newtonsoft.json.dll not handled in user code additional information: cannot deserialize current json object (e.g. {"name":"value"})...

sorry english, have idea doing wrong?

just quick tip, in visual studio, there's built-in feature convert json c# model.

you can find in edit\paste special\parse json classes

about question, model invalid, try this.

public class weatheritem {     public city city { get; set; }     public string cod { get; set; }     public float message { get; set; }     public int cnt { get; set; }     public list[] list { get; set; } }  public class city {     public int id { get; set; }     public string name { get; set; }     public coord coord { get; set; }     public string country { get; set; }     public int population { get; set; } }  public class coord {     public float lon { get; set; }     public float lat { get; set; } }  public class list {     public int dt { get; set; }     public temp temp { get; set; }     public float pressure { get; set; }     public int humidity { get; set; }     public weather[] weather { get; set; }     public float speed { get; set; }     public int deg { get; set; }     public int clouds { get; set; }     public float rain { get; set; } }  public class temp {     public float day { get; set; }     public float min { get; set; }     public float max { get; set; }     public float night { get; set; }     public float eve { get; set; }     public float morn { get; set; } }  public class weather {     public int id { get; set; }     public string main { get; set; }     public string description { get; set; }     public string icon { get; set; } } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -