title: DataContractJsonSerializer throws exception Expecting state 'Element'.. Encountered 'Text' with name '', namespace ''
body: <p>I need help to serialize a piece of json. </p>
  
  <p>I get a response from a rest service, the service is returning json. After that I want to map the request to a class. I'm using the DataContractJsonSerializer, but I can't get it to work. </p>
  
  <p>When the data is serialize the following exception is thrown:  </p>
  
  <pre><code>"Expecting state 'Element'.. Encountered 'Text'  with name '', namespace ''. "
  </code></pre>
  
  <p>Here is the code: </p>
  
  <pre><code>HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
  
  Stream responseStreamm = response.GetResponseStream();
  
  StreamReader reader = new StreamReader(responseStreamm);
  
  string streamAsString = reader.ReadToEnd();
  
  MemoryStream memoryStream = new MemoryStream(Encoding.Unicode.GetBytes(streamAsString)) {Position = 0};
  
  DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List&lt;MyClass&gt;));
  
  List&lt;MyClass&gt; myClass = (List&lt;MyClass&gt;)serializer.ReadObject(memoryStream);
  </code></pre>
  
  <p>And here is the MyClass:</p>
  
  <pre><code>[DataContract]
  public class MyClass
  {
      [DataMember]
      public string RawData { get; set; }
  
      [DataMember]
      public string StudentIdentity { get; set; }
  
      [DataMember]
      public string FirstName { get; set; }
  
      [DataMember]
      public string LastName { get; set; }
  
      [DataMember]
      public string SchoolName { get; set; }
  
      [DataMember]
      public string SchoolCode { get; set; }
  
      [DataMember]
      public string TypeOfEducation { get; set; }
  
      [DataMember]
      public string EducationCode { get; set; }
  
      [DataMember]
      public string NationalProgram { get; set; }
  
      [DataMember]
      public string Objective { get; set; }
  
      [DataMember]
      public string IssuingDate { get; set; }
  
      [DataMember]
      public string GradeType { get; set; }
  
      [DataMember]
      public string ProgramRange { get; set; }
  
      [DataMember]
      public string HourTotal { get; set; }
  
      [DataMember]
      public string BasicEligibility { get; set; }
  
      [DataMember]
      public string OccupationCompetence { get; set; }
  
      [DataMember]
      public string CourseOfStudyFromSchool { get; set; }
  
      [DataMember]
      public string Software { get; set; }
  
      [DataMember]
      public string SoftwareProvider { get; set; }
  
      [DataMember]
      public string ProgramType { get; set; }
  
      [DataMember]
      public string Note { get; set; }
  }
  </code></pre>
  
  <p>The response from the service is: </p>
  
  <pre><code>"[{\"RawData\":\"\",\"StudentIdentity\":\"450101\",\"FirstName\":\"Kalle\",\"LastName\":\"Karlsson\",\"SchoolName\":\"\",\"SchoolCode\":\"SKL123\",\"TypeOfEducation\":\"\",\"EducationCode\":\"Code\",\"NationalProgram\":\"\",\"Objective\":\"Obj\",\"IssuingDate\":\"2012-01-28\",\"GradeType\":\"GradeType\",\"ProgramRange\":\"1\",\"HourTotal\":\"2000\",\"BasicEligibility\":\"BE\",\"OccupationCompetence\":\"OC\",\"CourseOfStudyFromSchool\":\"Y\",\"Software\":\"HAL213\",\"SoftwareProvider\":\"SchoolSoft\",\"ProgramType\":\"C\",\"Note\":\"Notering\",\"CourseInformation\":[{\"CourseCode\":\"ABC555\",\"Grade\":\"VG\",\"GradeDate\":\"2012-01-28\",\"Points\":\"50\",\"Comment1\":\"Kommentar1\",\"Comment2\":\"\",\"Comment3\":\"\",\"AddtionalInformation\":\"Info\",\"Exceptions\":null},{\"CourseCode\":\"DFG333\",\"Grade\":\"G\",\"GradeDate\":\"2012-01-28\",\"Points\":\"60\",\"Comment1\":\"\",\"Comment2\":\"\",\"Comment3\":\"\",\"AddtionalInformation\":\"\",\"Exceptions\":null}],\"Exceptions\":[]}]"
  </code></pre>
  
  <p>Help is much appreciated! </p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>I'm complementing with the service code: </p>
  
  <pre><code>List&lt;MyClass&gt; myClass = validationManager.GetXmlAsAListOfEducationInformationObject();
  
  JavaScriptSerializerserializer = new JavaScriptSerializer();
  
  string jsonData = serializer.Serialize(myClass);
  
  return jsonData;
  </code></pre>