我想创建类以反序列化JSON。我尝试使用http://json2csharp.com/,但它不起作用。
JSON
{
"usertoken": "TqasdfgdSz0UleD-hdST5sigIE1MdOlKQ2HXrcvTwtCpveN9Fm",
"expires_sec": 12095,
"user": "testuser.com",
".expired": "Sat, 2 Jun 2018 09:25:00 GMT"
}
尝试使用以下课程但在.expired
班级成员
public class Authentication
{
public string usertoken { get; set; }
public int expires_sec { get; set; }
public string user { get; set; }
public string .expired { get; set; } //.will not work here
}
请建议
答案 0 :(得分:4)
你走在正确的轨道上。您需要使用的只是JsonProperty
。它将帮助您定义程序将使用的属性名称,并命名您的json字符串将在序列化和反序列化操作期间使用。
检查以下样本。
public class Authentication
{
public string usertoken { get; set; }
public int expires_sec { get; set; }
public string user { get; set; }
[JsonProperty (".expired")]
public string expired { get; set; }
}
您需要安装 Newtonsoft.Json nuget包才能实现此目的。