如何将txt或ohter格式转换为json和xml格式 [英] How to convert txt or ohter format to json and xml format

查看:105
本文介绍了如何将txt或ohter格式转换为json和xml格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想将数据转换为json和xml格式.您能帮我在这个网站上找到这些源代码吗?预先感谢.

Hi All,I want to convert data to json and xml format.Can you help me find these sourece codes at this website. Thanks in advance.

推荐答案



您的要求不清楚,但让我给您举个例子.并告诉我这是否适合您的情况.

检查以下代码,它将文本文件内容转换为xml.
Hi,

what you are asking is not clear, but let me give you example. and let me know if this is fit in your scenario.

check below code, it will convert your text file content into xml.
string str = "abc|xyz|pqr";
           string[] strsplit = str.Split('|');

           XDocument xdoc = new XDocument();
           XElement root = new XElement("Root");

           foreach (var item in strsplit)
           {
               root.Add(new XElement("item", item));
           }

           xdoc.Add(root);



输出:(xdoc对象内容)



Output :(xdoc object content)

<root>
  <item>abc</item>
  <item>xyz</item>
  <item>pqr</item>
</root>



满足您的要求吗?

谢谢
-Amit



is that fulfill your requirement ?

thanks
-Amit


这篇关于如何将txt或ohter格式转换为json和xml格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆