title: Deserialize object when property has IDictionary<string, string>
body: <p>I saw this but it doesnot help me.</p>
  
  <p><a href="https://stackoverflow.com/questions/45868180/deserializing-an-object-with-a-dictionarystring-object-property-newtonsoft-j">Deserializing an object with a Dictionary&lt;string, object&gt; property (Newtonsoft.Json)</a></p>
  
  <p>I am working on WCF Restful service. I have complicated JSON.
  I have below data contracts</p>
  
  <pre><code>[DataContract]
  public class TimestampPackageDC
  {
      [DataMember]
      public string Timestamp { get; set; }
  
      [DataMember]
      public string Company { get; set; }
  
      [DataMember]
      public string ContactID { get; set; }
  
      [DataMember]
      public string Area { get; set; }
  
      [DataMember]
      public string PackageID { get; set; }
  } // end of class TimestampPackageDC
  
  [DataContract]
  public class TimestampPackageExtraDC: TimestampPackageDC
  {
      [DataMember]
      public IDictionary&lt;string, string&gt; ExtraInfo { get; set; }
  } // end of class TimestampPackageExtraDC
  
  
   [DataContract]
  public class GetAllUnprintedItemsResponse: BaseResponse
  {
      [DataMember]
      public TimestampPackageDC[] TimestampPackages { get; set; }
  
      [DataMember]
      public TimestampPackageExtraDC[] TimestampExtraInfoPackages { get; set; }
  
  } 
  </code></pre>
  
  <p>I am making REST service call like below</p>
  
  <pre><code>GetAllUnprintedItemsResponse upResponse = new GetAllUnprintedItemsResponse();
  Request upRequest = new Request() { Name = "abc" };
  string url = "http://localhost:2023/myservice/getdata";
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  request.Method = "POST";
  request.ContentType = "application/json";
  byte[] data = Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(upRequest));
  request.ContentLength = data.Length;
  Stream requestStream = request.GetRequestStream();
  requestStream.Write(data, 0, data.Length);
  requestStream.Close();
  
  WebResponse response = request.GetResponse();
  Stream respStream = response.GetResponseStream();
  StreamReader reader = new StreamReader(respStream);
  string responseData = reader.ReadToEnd();
  
  //getting error below
  Newtonsoft.Json.JsonConvert.PopulateObject(responseData, upResponse);
  </code></pre>
  
  <p>I am getting JSON string like below</p>
  
  <pre><code>{
      "DocumentException": null,
      "Success": true,
      "TimestampExtraInfoPackages": [{
          "Area ": "AA",
          "Company": "XXX",
          "ContactID": "123",
          "PackageID": "P1",
          "Timestamp": "20090501163433360001",
          "ExtraInfo": [{
                  "Key": "Key1",
                  "Value": "value1"
              },
              {
                  "Key": "Key2",
                  "Value": "value2"
              }
          ]
      }],
      "TimestampPackages": []
  }
  </code></pre>
  
  <p>Below is the error I am getting</p>
  
  <p><strong>Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'System.Collections.Generic.IDictionary`2[System.String,System.String]' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
  To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) 
  like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
  Path 'TimestampExtraInfoPackages[0].ExtraInfo', line 1, position 194.</strong></p>
  
  <p><strong>SOLUTION:</strong></p>
  
  <p>Thanks to Shiva, Brian and taffer. I used taffer advice and it worked. It looks we cannot use IDictionary.</p>
  
  <p>I used below to solve my issue.</p>
  
  <pre><code>public List&lt;KeyValuePair&lt;string, string&gt;&gt; ExtraInfo { get; set; }
  </code></pre>
  
  <p>I tried below but did not work got same error.</p>
  
  <pre><code>public IDictionary&lt;string, string&gt;[] ExtraInfo { get; set; }
  </code></pre>