gpt4 book ai didi

c# - 无法将 json 转换为 xml

转载 作者:数据小太阳 更新时间:2023-10-29 02:00:43 30 4
gpt4 key购买 nike

我正在尝试将 json 字符串转换为 xml1) 我的 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"
}
]
}
]
]
}
]

2) 我的 C# 代码是

XmlDocument doc = JsonConvert.DeserializeXmlNode(str);

出现以下错误:

Error:--XmlNodeConverter can only convert JSON that begins with an object.

我尝试在 json 中进行少量编辑,例如 remove [] 问题元素。但没有奏效。

最佳答案

根据Mitchell Skurnikcomment ,您可以使用 JsonConvert.DeserializeXmlNode(JSONString, "root");

If your data is an array then you need to do something like this: JsonConvert.DeserializeXmlNode("{"Row":" + json + "}", "root").ToXmlString() otherwise you will get a "XmlNodeConverter can only convert JSON that begins with an object." exception.

– Mitchell Skurnik

Feb 17 '15 at 1:11

关于c# - 无法将 json 转换为 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35403588/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com