NET NewtonSoft JSON将映射反序列化为不同的属性名称下面是来自外部方的JSON字符串。{
"team":[
{
"v1":"",
"attributes":{
"eighty_min_score":"",
"home_or_away":"home",
"score":"22",
"team_id":"500"
}
},
{
"v1":"",
"attributes":{
"eighty_min_score":"",
"home_or_away":"away",
"score":"30",
"team_id":"600"
}
}
]}我的映射类:public class Attributes{
public string eighty_min_score { get; set; }
public string home_or_away { get; set; }
public string score { get; set; }
public string team_id { get; set; }}public class Team{
public string v1 { get; set; }
public Attributes attributes { get; set; }}public class RootObject{
public List<Team> team { get; set; }}问题是我不喜欢Attributes 类名而attributes 字段名在Team班级,等级。相反,我希望它被命名为TeamScore以及移除_从字段名,并给出正确的名字。JsonConvert.DeserializeObject<RootObject>(jsonText);我可以重命名Attributes到TeamScore,但是如果我更改字段名(attributes在Team类),它不会正确地反序列化,并给出null..我怎样才能克服这一切?
4 回答
- 4 回答
- 0 关注
- 3605 浏览
添加回答
举报
0/150
提交
取消