你这个Json不全,针对你现在的这个Json,可以用的代码是
[C#] 纯文本查看 复制代码 static Root JsonDeserialize(string JsonString)
{
return Newtonsoft.Json.JsonConvert.DeserializeObject<Root>(JsonString);
}
public class Root
{
/// <summary>
///
/// </summary>
public int code { get; set; }
/// <summary>
///
/// </summary>
public string msg { get; set; }
/// <summary>
/// body
/// </summary>
public Body body { get; set; }
public class Body
{
/// <summary>
/// periods
/// </summary>
public List<Periods> periods { get; set; }
public class Periods
{
/// <summary>
///
/// </summary>
public int id { get; set; }
/// <summary>
/// 典礼
/// </summary>
public string name { get; set; }
/// <summary>
///
/// </summary>
public string periodStatus { get; set; }
/// <summary>
///
/// </summary>
public long beginDate { get; set; }
/// <summary>
///
/// </summary>
public long endDate { get; set; }
/// <summary>
///
/// </summary>
public string isFreeStudy { get; set; }
/// <summary>
///
/// </summary>
public int sort { get; set; }
}
}
}
对了,你这个Json末尾我加了一点,不然解析不出来
[Asm] 纯文本查看 复制代码 {
"code": 1,
"msg": "success",
"body": {
"periods": [
{
"id": 103281,
"name": "典礼",
"periodStatus": "finish",
"beginDate": 1648209600000,
"endDate": 1648215000000,
"isFreeStudy": false,
"sort": 1
},
{
"id": 103282,
"name": "入门",
"periodStatus": "finish",
"beginDate": 1648296000000,
"endDate": 1648301400000,
"isFreeStudy": false,
"sort": 2
},
{
"id": 103283,
"name": "辅导",
"periodStatus": "finish",
"beginDate": 1648641600000,
"endDate": 1648647000000,
"isFreeStudy": false,
"sort": 3
}
]
}
}
方法是 先去https://www.toolscat.com/json/json-csharp,把你的Json粘贴进去,如果格式正确的话,就能生成实体类
把实体类一个个复制到代码里面去
然后调用Newtonsoft.Json.JsonConvert.DeserializeObject<Root>(JsonString);就能反而你要的数据了 |