我有一个像这样的字符串数组:
Array[2] = {"full product price", "hello world"}
但是当我反序列化它时,它变成了:
Array[5] = {"full", "product", "price", "hello", "world"}
也就是说,只要单词之间有空格,它就会在反序列化后作为单独的数组元素返回。
这是代码
XmlSerializer ser = new XmlSerializer(typeof(List<EntityResourceResourcePricePrice>));
if (!string.IsNullOrEmpty(hdfdeppricelist.Value))
{
string[] depprices = hdfdeppricelist.Value.Split(new string[] { "::" }, StringSplitOptions.None);
price.DependentPriceList = new string[depprices.Length];
price.DependentPriceList = depprices;
}
PriceList.Add(price);
lstpricelist.DataSource = PriceList;
lstpricelist.DataBind();
StringWriter sw = new StringWriter(new StringBuilder());
ser.Serialize(sw, PriceList);
hdfpricelist.Value = sw.GetStringBuilder().ToString();
在上面的代码中,我将在hdfdeppricelist.Value中将价格列表与“::”分开
这里price.DependentPriceList是字符串数组。我添加了2个元素,如“销售价格”,“成本价格”
然后我将整个价格添加到名为PriceList的列表中,然后将PriceList绑定到转发器。
所以,当我想编辑价格时,我为该转发器编写了item命令事件。这是
的代码if (hdfpricelist.Value != "")
{
List<EntityResourceResourcePricePrice> PriceList = new List<EntityResourceResourcePricePrice>();
XmlSerializer ser = new XmlSerializer(typeof(List<EntityResourceResourcePricePrice>));
StringReader sr = new StringReader(hdfpricelist.Value);
PriceList = (List<EntityResourceResourcePricePrice>)ser.Deserialize(sr);
EntityResourceResourcePricePrice errpp = PriceList[e.Item.DataItemIndex];
string[] DEP = errpp.DependentPriceList;
}
在上面的代码中,在字符串数组DEP中,我得到4个这样的元素:销售,价格,成本,价格