【发布时间】:2012-09-14 09:55:41
【问题描述】:
我需要显示 null 或零,而不是显示字符串为空。
Xml 响应:
<Items>
<Item>
<ASIN>111</ASIN>
<ItemAttributes>
<Title>xxx</Title>
<ListPrice>
<Currency>USD</Currency>
<FormattedPrice>45.25</FormattedPrice>
</ListPrice>
</ItemAttributes>
<Variation>
<Item>
<ItemAttributes>
<Title>yes</Title>
</ItemAttributes>
</Item>
</Variation>
</Item>
<Item>
<ASIN>222</ASIN>
<ItemAttributes>
<Title>yyy</Title>
</ItemAttributes>
<Variation>
<Item>
<ItemAttributes>
<Title>No</Title>
</ItemAttributes>
</Item>
</Variation>
</Item>
<Items>
这是我的代码。,
var Price1 = xd.Descendants(ns + "ListPrice").Select(c => new
{
PPrice = (c.Element(ns + "FormattedPrice") != null) ?
c.Element(ns + "FormattedPrice").Value : **string.Empty**
}).ToList();
如何将 String.Empty 替换为“Null”或 0 等值。提前致谢。 如果“FormattedPrice”不适用于项目二,则从 Xml 响应中,它应该 在列表中显示或为空。
【问题讨论】:
-
哪种情况为空,哪种情况为0?
-
@CuongLe 如果条件失败,这里显示 string.empty。而不是我必须显示任何文本,它可能是“Null”或数字“0”。
-
但显示错误“没有隐式转换 b/w 字符串和 int。
-
奇怪了,再试一下
"0"
标签: linq linq-to-xml