无法将json转换为xml

use*_*761 4 c# xml json

我试图将json字符串转换为xml 1)我的json是

[  
       {  
          "QuizTitle":"asdf",
          "QuizImage":"",
          "QuizCategory":"0",
          "QuizTags":"asdf",
          "question":[  
             [  
                {  
                   "QuestionType":"1",
                   "QuestionTitle":"asdf",
                   "questionOption":[  
                      {  
                         "QuestionOptionValue":"sdf",
                         "QuestionOptionIsRight":"0"
                      },
                      {  
                         "QuestionOptionValue":"asdf",
                         "QuestionOptionIsRight":"1"
                      }
                   ]
                }
             ],
             [  
                {  
                   "QuestionType":"2",
                   "QuestionTitle":"sdfdsf",
                   "questionOption":[  
                      {  
                         "QuestionOptionValue":"asdf",
                         "QuestionOptionIsRight":"0"
                      },
                      {  
                         "QuestionOptionValue":"asdf",
                         "QuestionOptionIsRight":"1"
                      }
                   ]
                }
             ]
          ]
       }
    ]
Run Code Online (Sandbox Code Playgroud)

2)我的c#代码是

XmlDocument doc = JsonConvert.DeserializeXmlNode(str);
Run Code Online (Sandbox Code Playgroud)

获得以下错误:

错误: - XmlNodeConverter只能转换以对象开头的JSON.

我想小编辑在json类似remove []的问题元素.但没有奏效.

Кон*_*Ван 11

根据Mitchell Skurnik评论,你可以使用JsonConvert.DeserializeXmlNode(JSONString, "root");.

如果您的数据是一个数组,那么您需要执行以下操作:JsonConvert.DeserializeXmlNode("{\"Row \":"+ json +"}","root").ToXmlString()否则您将获得"XmlNodeConverter"只能转换以对象开头的JSON." 例外.

- Mitchell Skurnik

2015年2月17日1:11