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 回答
- 0 關(guān)注
- 3637 瀏覽
添加回答
舉報
0/150
提交
取消