title: JavaScriptSerializer.Deserialize - how to change field names
body: <p><strong>Summary</strong>: How do I map a field name in JSON data to a field name of a .Net object when using JavaScriptSerializer.Deserialize ?</p>
  
  <p><strong>Longer version</strong>: I have the following JSON data coming to me from a server API (Not coded in .Net)</p>
  
  <pre><code>{"user_id":1234, "detail_level":"low"}
  </code></pre>
  
  <p>I have the following C# object for it:</p>
  
  <pre><code>[Serializable]
  public class DataObject
  {
      [XmlElement("user_id")]
      public int UserId { get; set; }
  
      [XmlElement("detail_level")]
      public DetailLevel DetailLevel { get; set; }
  }
  </code></pre>
  
  <p>Where DetailLevel is an enum with "Low" as one of the values.</p>
  
  <p>This test fails:</p>
  
  <pre><code>[TestMethod]
  public void DataObjectSimpleParseTest()
  {
      JavaScriptSerializer serializer = new JavaScriptSerializer();
      DataObject dataObject = serializer.Deserialize&lt;DataObject&gt;(JsonData);
  
      Assert.IsNotNull(dataObject);
      Assert.AreEqual(DetailLevel.Low, dataObject.DetailLevel);
      Assert.AreEqual(1234, dataObject.UserId);
  }
  </code></pre>
  
  <p>And the last two asserts fail, since there is no data in those fields. If I change the JSON data to</p>
  
  <pre><code> {"userid":1234, "detaillevel":"low"}
  </code></pre>
  
  <p>Then it passes. But I can't change the server's behaviour, and I want the client classes to have well-named properties in the C# idiom. I can't use LINQ to JSON since I want it to work outside of Silverlight. It looks like the XmlElement tags are having no effect. I don't know where I got the idea they were relevant at all, they probably aren't.</p>
  
  <p>How do you do field name mapping in JavaScriptSerializer? Can it be done at all?</p>