Sto utilizzando Newtonsoft Json per deserializzare la risposta di una chiamata ad un'API di OpenWeather Map, ma ricevo questo errore quando eseguo la pagina:
Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: S. Path '', line 0, position 0.'
Cosa sbaglio? Ecco il codice:
Sto cercando di familiarizzare con Json, quindi accetto ogni consiglio.codice:public partial class Default1 : System.Web.UI.Page { public class Main { public double temp { get; set; } public double temp_min { get; set; } public double temp_max { get; set; } public double pressure { get; set; } public double sea_level { get; set; } public double grnd_level { get; set; } public int humidity { get; set; } public double temp_kf { 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; } } public class Clouds { public int all { get; set; } } public class Wind { public double speed { get; set; } public double deg { get; set; } } public class Snow { public double? __invalid_name__3h { get; set; } } public class Sys { public string pod { get; set; } } public class List { public int dt { get; set; } public Main main { get; set; } public List<Weather> weather { get; set; } public Clouds clouds { get; set; } public Wind wind { get; set; } public Snow snow { get; set; } public Sys sys { get; set; } public string dt_txt { get; set; } } public class Coord { public double lat { get; set; } public double lon { 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 class RootObject { public string cod { get; set; } public double message { get; set; } public int cnt { get; set; } public List<List> list { get; set; } public City city { get; set; } } public class Account { public string Email { get; set; } public bool Active { get; set; } public DateTime CreatedDate { get; set; } public IList<string> Roles { get; set; } } public class Deserializza { public string Active { get; set; } public string Email { get; set; } } protected void Page_Load(object sender, EventArgs e) { Account account = new Account { Active = true, Email = "miaMail@tiscali.it" }; string json = JsonConvert.SerializeObject(account, Formatting.Indented); Deserializza deserializza = JsonConvert.DeserializeObject<Deserializza>(json); WebRequest request = WebRequest.Create("https://samples.openweathermap.org/data/2.5/forecast?id=524901&appid=mioAppID"); request.ContentType = "application/json"; WebResponse response = request.GetResponse(); string jsonRicevuto = response.ToString(); Main main = JsonConvert.DeserializeObject<Main>(jsonRicevuto); double prova = main.pressure; } }