0

我正在使用 ServiceStack.Text 在 Monotouch 上解析WorldWeatherOnline 的 Marine Api

这是错误“无法隐式转换类型DiveConditions.Model.Weather' toServiceStack.Text.JsonObject'”

这是违规的方法

JsonObject result = JsonObject.Parse(content).ConvertTo(x=> new Weather{

                        WeatherData = x.Object("weather").ConvertTo(w=> new WeatherData{

                            RequestDate = DateTime.Parse(x.Get("date")),
                            MinTempCentigrade = Convert.ToInt32(x.Get("mintempC")),
                            MaxTempCentigrade = Convert.ToInt32(x.Get("maxtempC")),
                            HourlyWeather = x.ArrayObjects("hourly").ConvertAll(h => new HourlyWeather{

                                CloudCover = Convert.ToInt32(h.Get("cloudcover")),
                                Humidity = Convert.ToInt32(h.Get ("humidity")),
                                Precipitation = Convert.ToDouble(h.Get ("precipitation")),
                                Pressure = Convert.ToInt32(h.Get ("pressure")),
                                SigWaveHeight = Convert.ToDouble(h.Get("sigHeight_m")),
                                SwellHeight = Convert.ToDouble(h.Get ("swellHeight_m")),
                                SwellDirection = Convert.ToInt32(h.Get("swellDir")),
                                SwellPeriod = Convert.ToDouble(h.Get ("swellPeriod_secs")),
                                TempCentigrade = Convert.ToInt32(h.Get("tempC")),
                                TempFahrenheit = Convert.ToInt32(h.Get("tempF")),
                                Time = Convert.ToInt32(h.Get("time")),
                                Visibility = Convert.ToInt32(h.Get("visibility")),
                                WaterTempCentigrade = Convert.ToInt32(h.Get("waterTemp_C")),
                                WaterTempFahrenheit = Convert.ToInt32(h.Get("waterTemp_F")),
                                WeatherCode = Convert.ToInt32(h.Get("weatherCode")),
                                WeatherIconUrl = h.Get("weatherIconUrl"),
                                WindDirection = h.Get("winddir16Point"),
                                WindDirectionDegrees = Convert.ToInt32(h.Get("winddirDegree")),
                                WindSpeedKmph = Convert.ToInt32(h.Get("windspeedKmph")),
                                WindSpeedMph = Convert.ToInt32(h.Get("windspeedMiles"))
                            })
                        }),

                        NearestArea = x.Object("nearest_area").ConvertTo(n => new NearestArea{

                            MilesFromReq = Convert.ToDouble(n.Get("distance_miles")),
                            RetLatitude = Convert.ToDouble(n.Get ("latitude")),
                            RetLongitude = Convert.ToDouble(n.Get ("longitude"))

                        }),
                        WeatherRequest = x.Object("request").ConvertTo(r=> new WeatherRequest{

                            Query = r.Get("query"),
                            RequestType = r.Get("type")
                        })
                    });

这是模型

public class Weather{

    public WeatherData WeatherData { get; set; }
    public NearestArea NearestArea { get; set; }        
    public WeatherRequest WeatherRequest {get; set;}
}

public class WeatherData
{
    public DateTime RequestDate     { get; set; }       
    public int MinTempCentigrade    { get; set; }
    public int MaxTempCentigrade    { get; set; }       
    public List<HourlyWeather> HourlyWeather { get; set; }      
}

public class NearestArea
{
    public double RetLatitude       { get; set; }
    public double RetLongitude      { get; set; }
    public double MilesFromReq      { get; set; }
}

public class WeatherRequest
{
    public string Query     { get; set; }
    public string RequestType       { get; set; }
}

public class HourlyWeather
{
    public int CloudCover           { get; set; }
    public int Humidity             { get; set; }
    public double Precipitation     { get; set; }
    public int Pressure             { get; set; }
    public int SwellDirection       { get; set; }
    public double SigWaveHeight { get; set; }
    public double SwellHeight       { get; set; }
    public double SwellPeriod       { get; set; }
    public int TempCentigrade       { get; set; }
    public int TempFahrenheit       { get; set; }
    public int Time             { get; set; }
    public int Visibility           { get; set; }
    public int WaterTempCentigrade  { get; set; }
    public int WaterTempFahrenheit  { get; set; }
    public int WeatherCode          { get; set; }
    public string WeatherIconUrl    { get; set; }
    public string WindDirection { get; set; }
    public int WindDirectionDegrees{ get; set; }
    public int WindSpeedKmph        { get; set; }
    public int WindSpeedMph     { get; set; }
}

谁能发现可能导致这种情况的原因?

提前致谢

4

0 回答 0