本文介绍了XML到Json序列化无法正常工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将XML序列化为JSON。从文件位置获取XML并将其运行到foreach语句以进行序列化。但问题是json的输出是
I'm trying to serialize XML to JSON. Getting the XML from a file location and running it to a foreach statement to serialize. But the thing is the output of the json is
{"ExtSerial":"KDI2015050501"} {"Date":"02/01/2015"} {"CustomerRefNbr":"15-000001"} {"Description":"2015 FEBRUARY RENTAL"} {"Customer":"TRDA0139"} {"Amount":"482072.5800"} {"AQ_Branch":"KDI"} {"AQ_COA":"4100503000"} {"LineSubAccount":"OPMOPN000"} {"LineTaxCategory":"False"} {"LineQuantity":"1"} {"LineUnitPrice":"482072.580000"} {"AQ_PostStatus":"0"} {"AQ_StatusDate":"02/01/2015"} {"DTS":"02/01/2015"} {"LineDescription":"Office Rental - Zero-Rated Sales"}这是XML:
Here is the XML:
<root><ExtSerial>KDI2015050501</ExtSerial> <Date>02/01/2015</Date> <CustomerRefNbr>15-000001</CustomerRefNbr> <Description>2015 FEBRUARY RENTAL</Description> <Customer>TRDA0139</Customer> <Amount>482072.5800</Amount> <AQ_Branch>KDI</AQ_Branch> <AQ_COA>4100503000</AQ_COA> <LineSubAccount>OPMOPN000</LineSubAccount> <LineTaxCategory>False</LineTaxCategory> <LineQuantity>1</LineQuantity> <LineUnitPrice>482072.580000</LineUnitPrice> <AQ_PostStatus>0</AQ_PostStatus> <AQ_StatusDate>02/01/2015</AQ_StatusDate> <DTS>02/01/2015</DTS> <LineDescription>Office Rental - Zero-Rated Sales</LineDescription></root>由于某种原因,没有root标签就行不了。 这是我的代码:
It won't work without the root tag for some reason. Here is my code:
static void Main(string[] args) { XElement xEle = XElement.Load(@"D:\Documents\Projects\HeXML\tae.xml"); IEnumerable<XElement> invoices = xEle.Elements(); foreach (var invoice in invoices) { Console.WriteLine(JsonConvert.SerializeXNode(invoice)); } Console.ReadLine(); }对不起。我想知道我哪里出错了。
I'm sorry. I want to know where I went wrong.
推荐答案看看过去的答案:在asp mvc中将xml远程转换为json [ ^ ] Have a look at past answer: remotly convert xml to json in asp mvc[^]
更多推荐
XML到Json序列化无法正常工作。
发布评论