我有以下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类名和属性字段名。相反,我希望它被命名为TeamScore,并从字段名称中删除_并给出正确的名称。
JsonConvert.DeserializeObject<RootObject>(jsonText);
我可以将Attributes重命名为TeamScore,但是如果我更改字段名称(Team类中的属性),它将不能正确地反序列化并返回null。我怎样才能克服这个问题呢?