2015-11-06 93 views
0

我想將xml文檔轉換爲json。在xml中,他們定義了每個標籤。我也想做這樣的XML到json轉換器的標籤

XML文檔:

    gameHistoryMain = new XDocument(
          new XElement("History", 
          new XElement("userid", playerID), 
          new XElement("gamedetails") 
          )); 

在這裏,我很困惑什麼JSON屬性是合適的?我試過

jsonObject JsonArray JsonProperty 

哪一個是正確的?

回答

1

導入Json.NetNuGet軟件包管理的軟件包

你的類文件中使用Newtonsoft.Json參考

using Newtonsoft.Json; 

下面的代碼片段可以幫助你的XDocument轉換成JSON

string json = JsonConvert.SerializeXNode(gameHistoryMain,Formatting.Indented,true); 

--SJ

+0

您的答案獲取數據爲XML格式,然後使用serializenode我可以改變爲JSON格式..在這裏我不需要的XML轉換。直接我想改變爲json格式。 –

+0

它解決了你的問題嗎?你仍然面臨任何問題? –

+0

什麼是您的源數據格式? –