C# 如何使用newtonsoft解析集合中的属性
请参见下面的XML。可比销售是一个重复项目。我正在使用新的NewtonSoft的Json解析器,我需要能够从元素中获取_Description属性的值,其中_type属性等于一个特定的字符串值,例如“grossbuildingara” 我使用下面的代码用newtsonsoft解析属性值,但我不知道如何获取属性C# 如何使用newtonsoft解析集合中的属性,c#,json,xml,vb.net,C#,Json,Xml,Vb.net,请参见下面的XML。可比销售是一个重复项目。我正在使用新的NewtonSoft的Json解析器,我需要能够从元素中获取_Description属性的值,其中_type属性等于一个特定的字符串值,例如“grossbuildingara” 我使用下面的代码用newtsonsoft解析属性值,但我不知道如何获取属性 <COMPARABLE_SALE PropertySequenceIdentifier="3" ProjectName="Villages of Devinshire" Projec
<COMPARABLE_SALE PropertySequenceIdentifier="3" ProjectName="Villages of Devinshire" ProjectPhaseIdentifier="1" PropertySalesAmount="132500" SalesPricePerGrossLivingAreaAmount="109.32" DataSourceDescription="FMLS, 5559496;DOM 80" DataSourceVerificationDescription="Tax Recs/2ndGen/Deeds" SalesPriceTotalAdjustmentPositiveIndicator="N" SalePriceTotalAdjustmentAmount="-1500" SalesPriceTotalAdjustmentGrossPercent="1.1" SalePriceTotalAdjustmentNetPercent="1.1" AdjustedSalesPriceAmount="131000">
<SALE_PRICE_ADJUSTMENT _Type="GrossBuildingArea"_Description="1,254"/>
<SALE_PRICE_ADJUSTMENT _Type="BasementArea" _Description="1,254 Sq.Ft."/>
<SALE_PRICE_ADJUSTMENT _Type="BasementFinish" _Description="1rr2ba4o"/>
</COMPARABLE_SALE>
如果您在(C#或VB.net)中有任何帮助,我们将不胜感激
谢谢,
Chaos要使用xml,请使用类似的xml api。这里有一个C#的例子:
var xml=@”
";
var xDoc=XDocument.Parse(xml);
var description=xDoc.Root.Elements(“销售价格调整”)
.First(e=>e.Attribute(“_Type”)。Value==“GrossBuildingArea”)
.属性(“描述”)
价值
要使用xml,请使用类似的xml api。这里有一个C#的例子:
var xml=@”
";
var xDoc=XDocument.Parse(xml);
var description=xDoc.Root.Elements(“销售价格调整”)
.First(e=>e.Attribute(“_Type”)。Value==“GrossBuildingArea”)
.属性(“描述”)
价值
在linq to xml中,您还可以使用子体和foreach来获取同一元素的所有值
var obj = from item in xDoc.Descendants("SALE_PRICE_ADJUSTMENT")
select new
{
_Descr = item.Attribute("_Description").Value,
_Type = item.Attribute("_Type").Value
};
在LINQtoXML中,还可以使用子体和foreach来获取同一元素的所有值
var obj = from item in xDoc.Descendants("SALE_PRICE_ADJUSTMENT")
select new
{
_Descr = item.Attribute("_Description").Value,
_Type = item.Attribute("_Type").Value
};
使用LINQ转换为XML不是更简单吗?我必须对这个文档进行大量解析,我正在其他地方使用Newtonsoft将XML序列化为Jobject,并希望保持一致。使用LINQ转换为XML不是更简单吗?我必须对这个文档进行大量解析,我正在使用Newtonsoft将XML序列化为JobjectNewtonsoft在其他地方,我希望保持它的一致性。
var obj = from item in xDoc.Descendants("SALE_PRICE_ADJUSTMENT")
select new
{
_Descr = item.Attribute("_Description").Value,
_Type = item.Attribute("_Type").Value
};