我有以下来自外部方的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; }
}
问题在于我不喜欢Team
类中的Attributes
类名和attributes
字段名称。相反,我希望它被命名为TeamScore
,并且删除字段名称中的_
并给出适当的名称。
JsonConvert.DeserializeObject<RootObject>(jsonText);
我可以将Attributes
重命名为TeamScore
,但如果我更改字段名称(Team
类中的attributes
),它将无法正确反序列化并给出null
。我该如何克服这个问题?