servicestack,C#,.net,Json,Xamarin.ios,servicestack" /> servicestack,C#,.net,Json,Xamarin.ios,servicestack" />

C# 无法转换模型类型。。。。。到ServiceStack.Text.JsonObject

C# 无法转换模型类型。。。。。到ServiceStack.Text.JsonObject,c#,.net,json,xamarin.ios,servicestack,C#,.net,Json,Xamarin.ios,servicestack,我正在使用ServiceStack.Text在Monotouch上解析 这是错误“无法将typeDiveConditions.Model.Weather”隐式转换为ServiceStack.Text.JsonObject” 这里有一个令人不快的方法 JsonObject result = JsonObject.Parse(content).ConvertTo(x=> new Weather{ WeatherData = x.Object("

我正在使用ServiceStack.Text在Monotouch上解析

这是错误“无法将type
DiveConditions.Model.Weather”隐式转换为
ServiceStack.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; }
}
公共类天气{
公共WeatherData WeatherData{get;set;}
公共近区近区{get;set;}
公共WeatherRequest WeatherRequest{get;set;}
}
公共类天气数据
{
公共日期时间请求日期{get;set;}
公共整数分钟摄氏度{get;set;}
public int MaxTempCentigrade{get;set;}
公共列表小时天气{get;set;}
}
公共舱近区
{
公共双纬度{get;set;}
公共双精度{get;set;}
公共双密耳FROMREQ{get;set;}
}
公共类天气请求
{
公共字符串查询{get;set;}
公共字符串请求类型{get;set;}
}
公共课小时天气
{
public int CloudCover{get;set;}
公共属性{get;set;}
公共双沉淀{get;set;}
公共int压力{get;set;}
公共整数膨胀方向{get;set;}
公共双SigWaveHeight{get;set;}
公共双膨胀重量{get;set;}
公共双膨胀周期{get;set;}
公共int温度摄氏度{get;set;}
公共温度{get;set;}
公共整数时间{get;set;}
公共int可见性{get;set;}
public int watertempcentide{get;set;}
公共int WaterTempFahrenheit{get;set;}
公共int天气代码{get;set;}
公共字符串WeatherIconUrl{get;set;}
公共字符串WindDirection{get;set;}
public int WindDirectionDegrees{get;set;}
公共int WindSpeedKmph{get;set;}
公共int windspeedph{get;set;}
}
有人能发现这可能是什么原因吗


提前感谢

您是否尝试将结果声明为
DiveConditions.Model.Weather result=..
而不是
JsonObject result=..
?答对了。干杯我觉得自己有点傻,因为我没试过……)