Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In my c# program I am using Newtonsoft to convert an xml to json.

I would like to convert a single node(version) from the following XML to an array since in most cases there are multiple nodes. When there are multiple versions the json converter automatically creates an array but doesn't when single.

I would like to force single version elements to arrays to use Angular ng-repeat consistently

Here is the XML

<versions>
  <testmode>true</testmode>
  <type>default</type>
  <version name="Test" url="http://myurl" />
</versions>

Which I convert with:

JsonConvert.SerializeXNode(xdoc);

When converted the json looks like:

"{\"Versions\":{\"testmode\":\"true\",\"type\":\"default\",\"version\":{\"name\":\"Test\",\"url\":\"http://myurl\"}}}"

I would like the version to be inside an array as:

"{\"Versions\":{\"testmode\":\"true\",\"type\":\"default\",\"version\":[{\"name\":\"Test\",\"url\":\"http://myurl\"}]}}"
share|improve this question
add comment (requires an account with 50 reputation)

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.