我有以下JSON字符串从外部方接收。.NET NewtonSoft 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; }
}
的问题是,我不喜欢“属性类”,并在团队类中的“属性字段名”。相反,我希望它被命名为“TeamScore”,并从字段名称中删除“_”并给出正确的名称。
JsonConvert.DeserializeObject<RootObject>(jsonText);
我可以改变的“属性”级到“TeamScore”,但如果我改变申请的域名(在Team类属性),它将无法正常反序列化,给我空。我该如何克服这一点?
清除,简洁的答案。尼斯。谢谢。也帮助了我。 FYI/Q?:输入错误 [JsonProperty(“team)id”] ...应该是下划线? – Aidanapword 2013-11-15 11:26:16
我可以使用两个JsonProperty的一个提交? – 2015-05-11 19:56:55
@AliYousefie不这么认为。但好的问题是,你期望从中得到什么? – outcoldman 2015-07-06 20:02:53