请问这个从网站API取得的JSON反序列化如果构建类?

bluespark 2017-09-12 02:05:22
{
"HeWeather5": [
{
"basic": {
"city": "镇江",
"cnty": "中国",
"id": "CN101190301",
"lat": "32.20440292",
"lon": "119.45275116",
"update": {
"loc": "2017-09-07 23:46",
"utc": "2017-09-07 15:46"
}
},
"daily_forecast": [
{
"astro": {
"mr": "19:07",
"ms": "06:19",
"sr": "05:41",
"ss": "18:19"
},
"cond": {
"code_d": "103",
"code_n": "101",
"txt_d": "晴间多云",
"txt_n": "多云"
},
"date": "2017-09-07",
"hum": "83",
"pcpn": "5.5",
"pop": "52",
"pres": "1010",
"tmp": {
"max": "27",
"min": "20"
},
"uv": "8",
"vis": "15",
"wind": {
"deg": "83",
"dir": "东风",
"sc": "微风",
"spd": "10"
}
},
{
"astro": {
"mr": "19:44",
"ms": "07:20",
"sr": "05:42",
"ss": "18:18"
},
"cond": {
"code_d": "101",
"code_n": "101",
"txt_d": "多云",
"txt_n": "多云"
},
"date": "2017-09-08",
"hum": "81",
"pcpn": "0.0",
"pop": "0",
"pres": "1011",
"tmp": {
"max": "29",
"min": "22"
},
"uv": "8",
"vis": "20",
"wind": {
"deg": "79",
"dir": "东风",
"sc": "微风",
"spd": "11"
}
},
{
"astro": {
"mr": "20:21",
"ms": "08:22",
"sr": "05:43",
"ss": "18:17"
},
"cond": {
"code_d": "104",
"code_n": "305",
"txt_d": "阴",
"txt_n": "小雨"
},
"date": "2017-09-09",
"hum": "85",
"pcpn": "0.0",
"pop": "1",
"pres": "1010",
"tmp": {
"max": "27",
"min": "23"
},
"uv": "5",
"vis": "19",
"wind": {
"deg": "97",
"dir": "东风",
"sc": "微风",
"spd": "13"
}
}
],
"status": "ok"
}
]
}



下面是我写的,[]表示阵列,好像最外面的HeWeather5没写对,请帮忙看一下
==========================================================================
public class HeWeather5
{
public Basic basic = new Basic();
public List<Dforecast> daliyForeast = new List<Dforecast>();
public string status { get; set; }
}
public class Basic
{
public string city { get; set; } //"city": "镇江",
public string cnty { get; set; } // "cnty": "中国",
public string id { get; set; } // "id": "CN101190301",
public string lat { get; set; } // "lat": "32.20440292",
public string lon { get; set; } // "lon": "119.45275116",
public Update update = new Update();
}

public class Update
{
public string loc { get; set; }
public string utc { get; set; }
}
public class Dforecast
{
public Astro astro = new Astro();
public Cond cond = new Cond();
public string date { get; set; }
public string hum { get; set; } //"hum": "83",
public string pcpn { get; set; } // "pcpn": "5.5",
public string pop { get; set; } // "pop": "52",
public string pres { get; set; } // "pres": "1010",
public Tmp tmp = new Tmp(); // "tmp": {
public string uv { get; set; } //"uv": "8",
public string vis { get; set; } // "vis": "15",
public Wind wind = new Wind();
}
public class Astro
{
public string mr { get; set; } // "mr": "19:07"
public string ms { get; set; } // "ms": "06:19"
public string sr { get; set; } // sr: "05:41"
public string ss { get; set; } // "ss": "18:19"
}
public class Cond
{
public string code_d { get; set; } // "code_d": "103",
public string code_n { get; set; } // "code_n": "101",
public string txt_d { get; set; } // "txt_d": "晴间多云",
public string txt_n { get; set; }// "txt_n": "多云"
}
public class Tmp
{
public string max { get; set; }
public string min { get; set; }
}
public class Wind
{
public string deg { get; set; }
public string dir { get; set; } // 风向
public string sc { get; set; }
public string spd { get; set; }
}
...全文
197 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluespark 2017-09-12
  • 打赏
  • 举报
回复
JSON里[]的我用List <>, IDE是自动生成数组。 当然我自己构建的类有问题,反序列化什么都出不来。 就是想问一下,Newtonsoft.dll 序列化支持List 么?
无名至 2017-09-12
  • 打赏
  • 举报
回复
http://tool.zhaotool.com/json/cdomain.html
bluespark 2017-09-12
  • 打赏
  • 举报
回复
谢谢楼上两位哥们。
正怒月神 2017-09-12
  • 打赏
  • 举报
回复
#1,2已经说了,就不多说了
  • 打赏
  • 举报
回复
Anonymous477 2017-09-12
  • 打赏
  • 举报
回复
复制这段json,在VS中打开一个cs文件并编辑,然后选择“编辑"->”选择性粘贴“->"将json粘贴为类",再稍作修改就可以了。

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧