0
我有一個類,有一個對象:Newtonsoft.Json反序列化XmlAnyAttribute?
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34283")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=true)]
public partial class Scores : baseModel
{
private System.Xml.XmlAttribute[] anyAttrField;
/// <remarks/>
[System.Xml.Serialization.XmlAnyAttributeAttribute()]
public System.Xml.XmlAttribute[] AnyAttr
{
get
{
return this.anyAttrField;
}
set
{
this.anyAttrField = value;
}
}
}
從父類(它的片段):
public parial class LandingPage : baseModel
{
private string projectNameField;
private Scores scoresField;
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string projectName
{
get { return this.projectNameField; }
set { this.projectNameField = value; }
}
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public Scores scores
{
get { return this.scoresField; }
set { this.scoresField = value }
}
}
JSON字符串我想一起工作:
{
"projectName":"PROJECTTEST",
"scores":{
"browLocker":100,
"heavyAd":0,
"walletRedirection":0
}
}
NewtonSoft.JsonConvert忽略了孩子的分數...領域
哪有我輕鬆將其轉換爲工作?
爲什麼Json.NET會關心XML屬性?爲什麼不創建一對真正匹配JSON文檔的類? –
爲什麼當你只能使用JSON時,試圖將JSON轉換爲XML會讓你的生活更加艱難? – Rafael
將您的'Scores'類改爲'class Scores {public int BrowLocker {get; set;} public int HeavyAd {get; set;} public int WalletRedirection {get; set;}}'。你不需要任何其他的反序列化這個字符串 –