Dav*_*xon 13 xml-attribute complextype
我在下面的类中收到以下错误:
无法序列化DataObjects.Ingredient类型的成员'Ingredient'.XmlAttribute/XmlText不能用于编码复杂类型.
有什么想法为什么?
[DataContract]
[Serializable]
[XmlRoot("ingredient")]
public class Ingredient
{
private string id;
private string name;
private string description;
private IngredientNutrient[] nutrients;
public Ingredient(string id, string name, string description, IngredientNutrient[] nutrients)
{
this.id = id;
this.name = name;
this.description = description;
this.nutrients = nutrients;
}
public Ingredient(string id, string name, string description)
{
this.id = id;
this.name = name;
this.description = description;
}
public Ingredient()
{
}
[DataMember]
[XmlAttribute("id")]
public string ID
{
get { return this.id; }
set { this.id = value; }
}
[DataMember]
[XmlAttribute("name")]
public string Name
{
get { return this.name; }
set { this.name = value; }
}
[DataMember]
[XmlAttribute("description")]
public string Description
{
get { return this.description; }
set { this.description = value; }
}
[DataMember]
[XmlArray("nutrients")]
[XmlArrayItem("ingredientnutrient")]
public IngredientNutrient[] Nutrients
{
get { return this.nutrients; }
set { this.nutrients = value; }
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10342 次 |
| 最近记录: |