Deserialize JSON data

I am getting responce in json as :

{"name":"Abhinav2","notification":[{"user1":"9123 ","user2":"123 ","createdTS":"1900-01-01T00:30:00.000Z","reviewId":null},{"user1":"9123 ","user2":"123 ","createdTS":"1900-01-01T00:30:00.000Z","reviewId":null}]}

in which name is string and notification holds an array. How to Deserialise it?

Best Answer


  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    you should create a Model like this

    public class Notification
        public string user1 { get; set; }
        public string user2 { get; set; }
        public string createdTS { get; set; }
        public object reviewId { get; set; }
    public class RootObject
        public string name { get; set; }
        public List<Notification> notification { get; set; }

    then use

    and do something like

    RootObject m = JsonConvert.DeserializeObject<RootObject>(yourstring);
  • shashitiwarishashitiwari USMember ✭✭

    @AlessandroCaliaro I am getting error this error.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    You should have a default constructor as the exception says...

    public RootObject(){}

  • saivignasaivigna Member ✭✭
    edited March 27

    {\"status\":\"success\" ,\"checklist\":[{\"ACTIVITY_ID\":\"II\",\"ID\":\"8\",\"VALIDATION_ID\":\"CC\",\"VALIDATION_NAME\":\"Condition Check\",\"ACTIVE_STATUS\":\"Y\"},
    {\"ACTIVITY_ID\":\"II\",\"ID\":\"8\",\"VALIDATION_ID\":\"CC\",\"VALIDATION_NAME\":\"Condition Check\",\"ACTIVE_STATUS\":\"Y\"}]}
    i am getting above as json response,how to Deserialize it and bind to listview.Thank u

Sign In or Register to comment.