XML到Json序列化无法正常工作。

编程入门 行业动态 更新时间:2024-10-10 19:26:25
本文介绍了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序列化无法正常工作。

本文发布于:2023-11-12 13:08:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581590.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   序列化   工作   XML   Json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!