JSON

How to Json To Xml

字号+ 作者:H5之家 来源:H5之家 2015-10-30 16:25 我要评论( )

I am new for Json and I have a simple problem.[我是新的JSON和我有一个简单的问题。]

I am new for Json and I have a simple problem.

I am trying to convert json file to xml file with c#. But it throw an exception.

The Code is ;

private void TakeXML() { string json = ReadText(); XmlDocument doc = (XmlDocument)Newtonsoft.Json.JsonConvert.DeserializeXmlNode(json); XmlTextWriter writer = new XmlTextWriter("json.xml", null); writer.Formatting = Formatting.Indented; doc.Save(writer); }

The ReadText function is;

private string ReadText() { FileStream fs = new FileStream(@"C:\Users\Sinan\Desktop\bina.json", FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); string json; try { json = sr.ReadToEnd(); return json; } catch (Exception) { return null; } finally { sr.Close(); fs.Dispose(); } }

for XmlDocument doc = (XmlDocument)Newtonsoft.Json.JsonConvert.DeserializeXmlNode(json); line, it said that;

"JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName."

I am searching to solve this problem but haven't found it. f you help me in this regard, I will be glad. Thank you.

我是新的JSON和我有一个简单的问题。

我想转换成JSON文件与C # XML文件。但它抛出一个异常。

该代码是;

private void TakeXML() { string json = ReadText(); XmlDocument doc = (XmlDocument)Newtonsoft.Json.JsonConvert.DeserializeXmlNode(json); XmlTextWriter writer = new XmlTextWriter("json.xml", null); writer.Formatting = Formatting.Indented; doc.Save(writer); }

READTEXT函数;

private string ReadText() { FileStream fs = new FileStream(@"C:\Users\Sinan\Desktop\bina.json", FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); string json; try { json = sr.ReadToEnd(); return json; } catch (Exception) { return null; } finally { sr.Close(); fs.Dispose(); } }

为XmlDocument doc = (XmlDocument)Newtonsoft.Json.JsonConvert.DeserializeXmlNode(json);线的,它说;

“JSON根对象具有多个属性。根对象必须以创造一个有效的XML文档有一个单一的财产。考虑一个deserializerootelementname化。”

我寻找解决这一问题,但没找到。如果你在这方面帮助我,我会很高兴的。谢谢你

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • php CI 实战教程:[5]用curl获取json并解析

    php CI 实战教程:[5]用curl获取json并解析

    2016-02-26 17:00

  •  JSON入门级学习总结-JSON数据结构

    JSON入门级学习总结-JSON数据结构

    2016-02-25 11:05

  • Android解析Json速度最快的库:json

    Android解析Json速度最快的库:json

    2016-02-13 18:00

  • JavaScript转换与解析JSON方法实例详解第1/2页

    JavaScript转换与解析JSON方法实例详解第1/2页

    2016-02-10 21:25

网友点评
=