我有以下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