chamila99 Perera chamila99 Perera - 3 months ago 8
JSON Question

Deserialize Json Using NewtonJS

I have WCF Rest service Returns Json , I Get the response Json string but after De-serializing It gives Null object ,Json contains response object which contains List , before De-serializing string json string shows 3 DTOStundet objects after De-serializing List shows null

string returnValue = Navigator.GET(url, APIHearderCollection);

{
"GetStudentsListJSONResult":
{
"response":
{
"DTOStudentList":[
{
"Address":"Kandy",
"Age":20,
"CourseName":"Physical Sience",
"DateOfBirth":"\/Date(318191400000+0530)\/",
"StudentId":1,"StudentName":"Kumar Sangakkara",
"TelePhoneNumber":"071975769"
},
{
"Address":"Colombo",
"Age":21,"CourseName":"Physical Sience",
"DateOfBirth":"\/Date(2658600000+0530)\/",
"StudentId":2,"StudentName":"Mahela Jayawardena",
"TelePhoneNumber":"071975759"
}
],
"ResponseStatus":0
}
}
}


returnValue contain this json string to be De-serialize

image description here]1

this is where im De-serializing json after this response gets null

Response response = (Response)Newtonsoft.Json.JsonConvert.DeserializeObject(returnValue, typeof(Response));

Answer

You can deserialize this way, create separate model class

public class NewModel
{
    public Response GetStudentsListJSONResult { get; set; };
}

public class NewModel2
{
    public NewModel Result { get; set; };
}

Then

NewModel2 response = Newtonsoft.Json.JsonConvert.DeserializeObject<NewModel2>(returnValue); 
Comments