I'm trying to get JSON data from Web API and then show it in tabular form in the MVC application. But receiving null values after using deserialization.
JSON file :
[{
"Students": [
{
"id": 1,
"name": "Ravi",
"department": "IT"
},
{
"id": 2,
"name": "Raj",
"department": "hr"
},
{
"id": 3,
"name": "avi",
"department": "it"
},
{
"id": 4,
"name": "rome",
"department": "HR"
}
]
}]
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public string Department { get; set; }
}
[HttpGet]
public async Task<List<Student>> GetAllStudents()
{
/// Ostudent = new Student()
using (var httpclient = new HttpClient())
{
using (var response = await httpclient.GetAsync("https://localhost:7232/api/Student"))
{
string res = await response.Content.ReadAsStringAsync()
OStudents = JsonConvert.DeserializeObject<List<Student>>(res);
}
}
return OStudents ;
}
I'm trying to get value in response (res) but getting null from OStudents.