I have following JSON string which is received from an external party.
{
"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"
}
}
]
}
我的 map 类:
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
class name和attributes
field names.相反,我希望将其命名为TeamScore
,并从字段名中删除_
,并给出正确的名称.
JsonConvert.DeserializeObject<RootObject>(jsonText);
我可以将Attributes
重命名为TeamScore
,但如果我更改字段名(Team
类中的attributes
),它将无法正确反序列化,并给出null
.我怎样才能克服这个问题?