Link to home
Start Free TrialLog in
Avatar of breezback
breezbackFlag for Israel

asked on

JSON deserialization issue

Hi,

Trying to deserialize this JSON string to a proper object to manipulate later.

[*] Attaching the JSON String

It's urgent :) Somehow it doesn't out, I'm using Newton JsonConverter

var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<JSON>(jsonStr);

Open in new window


    public class JSON
    {
        public Data data { get; set; }
    }

    public class Data
    {
        public Request request { get; set; }
        public NearestArea nearest_area { get; set; }
        public Weather weather { get; set; }
    }

    public class Weather
    {
        public string date { get; set; }
        public string maxtempC { get; set; }
        public string mintempC { get; set; }
        public IList<Hourly> hourly { get; set; }
    }

    public class Hourly
    {
        public string cloudcover,
                      humidity,
                      precipMM,
                      pressure,
                      sigHeight_m,
                      swellDir,
                      swellHeight_m,
                      swellPeriod_secs,
                      tempC,
                      tempF,
                      time,
                      visibility,
                      waterTemp_C,
                      waterTemp_F,
                      weatherCode,
                      winddir16Point,
                      winddirDegree,
                      windspeedKmph,
                      windspeedMiles;

        public WeatherIconUrl weatherIconUrl;

    }

    public class WeatherIconUrl
    {
        public string value;
    }

    public class NearestArea
    {
        public string distance_miles { get; set; }
        public string latitude { get; set; }
        public string longitude { get; set; }
    }

    public class Request
    {
        public string type { get; set; }
        public string query { get; set; }
    }

Open in new window


currently stuck on Exception:
Expected a JsonObjectContract or JsonDictionaryContract for type 'IKayak.Schemas.Contracts.Forecasts.NearestArea', got 'Newtonsoft.Json.Serialization.JsonObjectContract'.
ASKER CERTIFIED SOLUTION
Avatar of breezback
breezback
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you deserialize in the correct object?

HTH

Ivo Stoykov