0
votes

I want to deserialize an jsonData, I will put the class and json data i am getting here.

This is the Json:

{
  "$id":"1",
  "Success":true,
  "Message":[],
  "Data: [
    {
      "$id":"2",
      "ID":1,
      "StudentCount":"30",
      "Boys":"15",
      "Girls":"15",
      "EntryDate":"2013-06-12T00:00:00"
    }
  ]
}

this is what I have written to deserialize. I am not getting any error but showing the same data as json

WebClient wc = new WebClient();
string json = wc.DownloadString("http://localhost:43293/api/Common");
var oc = JsonConvert.DeserializeObject(json);

This is the class:

public class Outcome
   {
      public bool Success { get; set; }
      public List Message { get; set; }
      public object Data { get; set; }
      public Outcome()
         {
            Message = new List();
         }
    }
1
Ok... what's your question?Jeff Mercado
I am not able to deserialize object public object Data { get; set; },nayas_sub3431732

1 Answers

0
votes

the problem is that your Json-object Data cannot be deserialized to an instance of the C#-type object, since you are not giving a concrete class that provides properties for $id, ID, StudentCount, ...

Try to introduce a concrete class for your property Data or deserialize into a dynamic object:

dynamic oc = JsonConvert.Deserialize(json);