C#JSON将值3072转换为类型'时出错;WeatherUnderground.RootObject';
我正在尝试从这里反序列化json: 我以这种方式反序列化:C#JSON将值3072转换为类型'时出错;WeatherUnderground.RootObject';,c#,json,json.net,C#,Json,Json.net,我正在尝试从这里反序列化json: 我以这种方式反序列化: RootObject oData = JsonConvert.DeserializeObject<RootObject>(jsonResponse.ContentString); RootObject oData=JsonConvert.DeserializeObject(jsonResponse.ContentString); 我曾经创建过我的C#类 public class Features { p
RootObject oData = JsonConvert.DeserializeObject<RootObject>(jsonResponse.ContentString);
RootObject oData=JsonConvert.DeserializeObject(jsonResponse.ContentString);
我曾经创建过我的C#类
public class Features
{
public int hourly10day { get; set; }
}
public class Response
{
public string version { get; set; }
public string termsofService { get; set; }
public Features features { get; set; }
}
public class FCTTIME
{
public string hour { get; set; }
public string hour_padded { get; set; }
public string min { get; set; }
public string min_unpadded { get; set; }
public string sec { get; set; }
public string year { get; set; }
public string mon { get; set; }
public string mon_padded { get; set; }
public string mon_abbrev { get; set; }
public string mday { get; set; }
public string mday_padded { get; set; }
public string yday { get; set; }
public string isdst { get; set; }
public string epoch { get; set; }
public string pretty { get; set; }
public string civil { get; set; }
public string month_name { get; set; }
public string month_name_abbrev { get; set; }
public string weekday_name { get; set; }
public string weekday_name_night { get; set; }
public string weekday_name_abbrev { get; set; }
public string weekday_name_unlang { get; set; }
public string weekday_name_night_unlang { get; set; }
public string ampm { get; set; }
public string tz { get; set; }
public string age { get; set; }
public string UTCDATE { get; set; }
}
public class Temp
{
public string english { get; set; }
public string metric { get; set; }
}
public class Dewpoint
{
public string english { get; set; }
public string metric { get; set; }
}
public class Wspd
{
public string english { get; set; }
public string metric { get; set; }
}
public class Wdir
{
public string dir { get; set; }
public string degrees { get; set; }
}
public class Windchill
{
public string english { get; set; }
public string metric { get; set; }
}
public class Heatindex
{
public string english { get; set; }
public string metric { get; set; }
}
public class Feelslike
{
public string english { get; set; }
public string metric { get; set; }
}
public class Qpf
{
public string english { get; set; }
public string metric { get; set; }
}
public class Snow
{
public string english { get; set; }
public string metric { get; set; }
}
public class Mslp
{
public string english { get; set; }
public string metric { get; set; }
}
public class HourlyForecast
{
public FCTTIME FCTTIME { get; set; }
public Temp temp { get; set; }
public Dewpoint dewpoint { get; set; }
public string condition { get; set; }
public string icon { get; set; }
public string icon_url { get; set; }
public string fctcode { get; set; }
public string sky { get; set; }
public Wspd wspd { get; set; }
public Wdir wdir { get; set; }
public string wx { get; set; }
public string uvi { get; set; }
public string humidity { get; set; }
public Windchill windchill { get; set; }
public Heatindex heatindex { get; set; }
public Feelslike feelslike { get; set; }
public Qpf qpf { get; set; }
public Snow snow { get; set; }
public string pop { get; set; }
public Mslp mslp { get; set; }
}
public class RootObject
{
public Response response { get; set; }
public IList<HourlyForecast> hourly_forecast { get; set; }
}
公共类功能
{
公共时间10天{get;set;}
}
公众课堂反应
{
公共字符串版本{get;set;}
公共字符串项服务{get;set;}
公共要素{get;set;}
}
公共类时间
{
公共字符串hour{get;set;}
公共字符串hour_填充{get;set;}
公共字符串min{get;set;}
公共字符串min_unpadded{get;set;}
公共字符串sec{get;set;}
公共字符串年份{get;set;}
公共字符串mon{get;set;}
公共字符串mon_填充{get;set;}
公共字符串mon_abbrev{get;set;}
公共字符串mday{get;set;}
公共字符串mday_填充{get;set;}
公共字符串yday{get;set;}
公共字符串isdst{get;set;}
公共字符串{get;set;}
公共字符串{get;set;}
公共字符串civil{get;set;}
公共字符串month_name{get;set;}
公共字符串month_name_abbrev{get;set;}
公共字符串weekday_name{get;set;}
公共字符串weekday_name_night{get;set;}
公共字符串weekday_name_abbrev{get;set;}
公共字符串weekday_name_unlang{get;set;}
公共字符串weekday_name_night_unlang{get;set;}
公共字符串ampm{get;set;}
公共字符串tz{get;set;}
公共字符串年龄{get;set;}
公共字符串UTCDATE{get;set;}
}
公共类临时工
{
公共字符串英语{get;set;}
公共字符串度量{get;set;}
}
公共级露点
{
公共字符串英语{get;set;}
公共字符串度量{get;set;}
}
公共类Wspd
{
公共字符串英语{get;set;}
公共字符串度量{get;set;}
}
公共类Wdir
{
公共字符串dir{get;set;}
公共字符串度数{get;set;}
}
公共级风寒机
{
公共字符串英语{get;set;}
公共字符串度量{get;set;}
}
公营热指数
{
公共字符串英语{get;set;}
公共字符串度量{get;set;}
}
公共课的感觉
{
公共字符串英语{get;set;}
公共字符串度量{get;set;}
}
公共类Qpf
{
公共字符串英语{get;set;}
公共字符串度量{get;set;}
}
公共类雪
{
公共字符串英语{get;set;}
公共字符串度量{get;set;}
}
公共类Mslp
{
公共字符串英语{get;set;}
公共字符串度量{get;set;}
}
公共课小时预测
{
公共FCTTIME FCTTIME{get;set;}
公共临时{get;set;}
公共露点露点{get;set;}
公共字符串条件{get;set;}
公共字符串图标{get;set;}
公共字符串图标\u url{get;set;}
公共字符串fctcode{get;set;}
公共字符串sky{get;set;}
公共Wspd Wspd{get;set;}
公共Wdir Wdir{get;set;}
公共字符串wx{get;set;}
公共字符串uvi{get;set;}
公共字符串{get;set;}
公共Windchill Windchill{get;set;}
公共热索引热索引{get;set;}
公共感觉就像{get;set;}
公共Qpf Qpf{get;set;}
公共雪地{get;set;}
公共字符串pop{get;set;}
公共Mslp Mslp{get;set;}
}
公共类根对象
{
公共响应{get;set;}
公共IList每小时_预测{get;set;}
}
但我仍然得到:
将值3072转换为类型“WeatherUnderground.RootObject”时出错位于Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(对象值,类型targetType)
我做错了什么?
另外,如果与此有关,我正在使用.NET3.5
谢谢
Json:
您的json和类结构如下所示
RootObject oData = JsonConvert.DeserializeObject<RootObject>(jsonResponse.ContentString);
当我这样做的时候,它给了我适当的结果
RootObject oData = JsonConvert.DeserializeObject<RootObject>(jsonResponse.ContentString);
RootObject oData=JsonConvert.DeserializeObject(jsonResponse.ContentString);
Json:
您的json和类结构如下所示
RootObject oData = JsonConvert.DeserializeObject<RootObject>(jsonResponse.ContentString);
当我这样做的时候,它给了我适当的结果
RootObject oData = JsonConvert.DeserializeObject<RootObject>(jsonResponse.ContentString);
RootObject oData=JsonConvert.DeserializeObject(jsonResponse.ContentString);
报告您得到的json,您发布的链接参考文档:我无法重现json和类的错误,因为您看到这个问题,因为C#类与json数据不匹配。试着使用这个网站,需要5秒钟才能让你想要的类报告你得到的json,你发布的链接参考文档:我无法重现json和类的错误,因为你的C#类与json数据不匹配。试着使用这个网站,你需要5秒才能得到你想要的课程