gpt4 book ai didi

complextype - XmlAttribute/XmlText 不能用于编码复杂类型

转载 作者:行者123 更新时间:2023-12-03 22:52:17 25 4
gpt4 key购买 nike

我在以下类(class)中收到以下错误:

无法序列化 DataObjects.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; }
}

}

最佳答案

您可能必须使用 [XmlElement]而不是 [XmlAttribute] .属性不能是复杂类型。

关于complextype - XmlAttribute/XmlText 不能用于编码复杂类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16759748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com