hello,
I am getting response output from Postman as -
{
Result :
{
Id : 1,
Name : Ramesh,
Designation : Manager
}
}
So in my mvc web api project, I'm getting Result , but i want separate property of it, something like :
HCOutput output = New HCOutput();
var aa = output.Result.Name;
output.Result.Id;
so how it can be done? is it serialization ?

Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 3, 2023, 10:32 AM EST
Hello Sushant,
You need to create below class which will parse the response:
public class Result { public int Id { get; set; } public string Name { get; set; } public string Designation { get; set; } }You can than Deserialize respones as below.
Thanks
Naimish
Sushant TorankarRank #3,026 · 476 reputationPosted Feb 3, 2023, 11:35 AM EST
Thank you Naimish Makwana for reply
Result is a already Object in my Class clsResponse
public class Result
{
public string status{ get; set; }
public string error{ get; set; }
public Object Result{ get; set; }
}
I'm getting response in my Object Result
{
status : "success",
error : "",
Result :
{
Id : 1,
Name : Ramesh,
Designation : Manager
}
}
, i have to then get Id or Name or Designation separately
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 3, 2023, 11:52 AM EST
Hello Sushant,
You need to create class like below.
public class Response { public string status { get; set; } public string error { get; set; } public Result Result { get; set; } } public class Result { public int Id { get; set; } public string Name { get; set; } public string Designation { get; set; } }Then
Thanks
Naimish
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 3, 2023, 12:11 PM EST
Hello Sushant
Try below code as you want.
public class Result { public string status { get; set; } public string error { get; set; } public object Result { get; set; } }then
Root root = JsonConvert.DeserializeObject(json); JObject result = (JObject)root.Result; int id = (int)result["Id"]; string name = (string)result["Name"];Thanks.