i am trying to convert json string to xml 1) my json is
[
{
"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) my c# code is
XmlDocument doc = JsonConvert.DeserializeXmlNode(str);
Getting following error:
Error:--XmlNodeConverter can only convert JSON that begins with an object.
i tried to little edit in json
like remove []
for question element. but not worked.
According to the Mitchell Skurnik's comment, you can use 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With