2016-01-24 42 views
0

过去2个小时我试图将xml解析为json。 在我做我做到了这样一个例子项目:我如何将XML转换为json(不使用Json.NET)

string xmlString = XDocument.Load("G00011071.xml").ToString(); 
XmlDocument xml = new XmlDocument(); 
xml.LoadXml(xmlString); 

var json = Newtonsoft.Json.JsonConvert.SerializeObject(xml); 

,它工作得很好..

当我试图把它的一个项目,我需要使用它有 我得到整合错误:

An exception of type 'System.IO.FileLoadException' occurred in xmloutput.dll but was not handled in user code. Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

我试图解决这个问题,但没有任何帮助 - 所以我决定不使用 Json.net和寻找替代品,我发现post

,但我的XML结构复杂得多然后使用那里的一个..

我怎样才能达到同样的结果作为一个Json.net产生的?

+0

你能上传你的xml文件吗? – ganchito55

+0

我如何发布它,这里非常长..? –

+1

http://pastebin.com/例如 – ganchito55

回答

0

您引用的程序集和可用的程序集之间似乎存在版本不匹配。如果您有多个项目,请确保它们都使用相同版本的Json.NET。 Json.NET是作业的工具,编写已经作为经过验证的库(然后测试和维护它)的代码是不值得的。

+0

中有一个旧版本的newsoft.json,在我的解决方案中有2个项目,但此解决方案是部分的另一种解决方案 - 另一种解决方案包含“牛顿软件” - 所以版本之间存在不匹配。 谢谢 –