title: SQL Server XML result, convert to JSON using C#, and JavaScriptSerializer()?
body: <p>Ok, I'm a little stuck here. I can get my query and return my data as XML. That's not the problem.</p>
  
  <p>I can create an XDocument. That's not the problem.</p>
  
  <p>What I would like to be able to do is turn my XML:</p>
  
  <pre><code>&lt;DATA&gt;
  &lt;row&gt;
      &lt;PersonName&gt;Hank Scorpio&lt;/PersonName&gt;
  &lt;/row&gt;
  &lt;row&gt;
      &lt;PersonName&gt;Sgt. Pepper&lt;/PersonName&gt;
  &lt;/row&gt;
  &lt;row&gt;
      &lt;PersonName&gt;Dr. Sheldon Cooper&lt;/PersonName&gt;
  &lt;/row&gt;
  &lt;/DATA&gt;
  </code></pre>
  
  <p>Into JSON. I tried using the dictionary, and something like this:</p>
  
  <pre><code>var d = xdoc.Descendants("row")
  .ToDictionary(val =&gt; val.Element("PersonName").Name.LocalName, val =&gt; val.Element("PersonName").Value);
  </code></pre>
  
  <p>But that kept giving me a duplicate value error.</p>
  
  <p>Then I considered using a List of strings instead of a dictionary. I'm a bit reluctant to do that, though.</p>
  
  <p>I only have 1189 records to do, but my fear is if it grows too much, even with the given capacity of a list, it may not be the best way to go.</p>
  
  <p>So basically I want to turn the above XML into something like this:</p>
  
  <pre><code>{
    "DATA": {
      "row": [
        { "PersonName": "Hank Scorpio" },
        { "PersonName": "Sgt. Pepper" },
        { "PersonName": "Dr. Sheldon Cooper" }
      ]
    }
  }
  </code></pre>
  
  <p>Or, to save myself some strife, should I just go ahead and do the list? For the application I am building this for, I am sending the values to an API, but they're currently deciding if they also want an ID for the record. So I'm trying to figure out a solution that won't require a large re-write should they change their minds later.</p>
  
  <p>We're using VS2015, so I don't think we have some of the newer C# features.</p>
  
  <p>Any thoughts or ideas?</p>