I have ASP.NET Web API
Its returning JSON like this
{
"Status": "success",
"StatusCode": 605,
"Data": [
{
"SiteGuid": "cb36a2f2-0793-46d5-a9f4-03531310bcd2122",
"Site": "**",
"flagSet": 0
},
{
"SiteGuid": "c358229e-3ed3-446e-890d-fffa67008642123",
"Site": "**",
"flagSet": 0
},
{
"SiteGuid": "426a3694-0703-4094-840e-eab8afe402c4123",
"Site": "**",
"flagSet": 0
}
]
}
But I need to return JSOn Object instead of it
[{
"id": "",
"contactListId": "***************",
"data": {"Service Line": "8888",
"Problem Type Code": "123",
"Problem Type Desc": "Water problem",
"Request Priority": "1",
"Supplier": "XYZ",
"Site": "***",
"Unit#": "1001",
"Request Creation Date":"25/02/2022",
"Request Closure Date": "03/03/2022",
"Mobile (MSISDN)":"+****",
"EXT#": "2002",
"Customer's Name": "***",
"Customer's eMail": "*****",
"TimeZone":"****"
},
"callable": true,
"phoneNumberStatus": {}
},
{
"id": "",
"contactListId": "***************",
"data": {"Service Line": "8888",
"Problem Type Code": "123",
"Problem Type Desc": "Water problem",
"Request Priority": "1",
"Supplier": "XYZ",
"Site": "***",
"Unit#": "1001",
"Request Creation Date":"25/02/2022",
"Request Closure Date": "03/03/2022",
"Mobile (MSISDN)":"+****",
"EXT#": "2002",
"Customer's Name": "***",
"Customer's eMail": "*****",
"TimeZone":"****"
},
"callable": true,
"phoneNumberStatus": {}
}]
How I need to modify my controller?
TIA

Anoop Kumar SharmaPosted Apr 2, 2022, 5:59 AM
Ajaz KhanPosted Apr 12, 2022, 11:51 AM
Hi All,
I implemented blow class for getting above json formating but i am not getting properly data values ,data values seeing null and need the above format json data. Please kindly suggest me ,how i can achieve that.
Model....
public class Data
{
[JsonProperty("Service Line")]
public string ServiceLine { get; set; }
[JsonProperty("Problem Type Code")]
public string ProblemTypeCode { get; set; }
[JsonProperty("Problem Type Desc")]
public string ProblemTypeDesc { get; set; }
[JsonProperty("Request Priority")]
public string RequestPriority { get; set; }
public string Supplier { get; set; }
public string Site { get; set; }
[JsonProperty("Unit#")]
public string Unit { get; set; }
[JsonProperty("Request Creation Date")]
public string RequestCreationDate { get; set; }
[JsonProperty("Request Closure Date")]
public string RequestClosureDate { get; set; }
[JsonProperty("Mobile (MSISDN)")]
public string MobileMSISDN { get; set; }
[JsonProperty("EXT#")]
public string EXT { get; set; }
[JsonProperty("Customer's Name")]
public string CustomerSName { get; set; }
[JsonProperty("Customer's eMail")]
public string CustomerSEMail { get; set; }
public string TimeZone { get; set; }
}
public class PhoneNumberStatus
{
}
public class Root
{
public string id { get; set; }
public string contactListId { get; set; }
public Data data { get; set; }
public string callable { get; set; }
public PhoneNumberStatus phoneNumberStatus { get; set; }
}
-------------------------------------------------------------------------------------------------------------
controller...
[HttpGet]
public IEnumerable GetClosedSeviceRequest()
{
try
{
List Model = new List();
DataTable dt = new DataTable();
if (Provider == "SQL")
dt = QueryHelper.GetServiceRequestSQL();
else
dt = QueryHelper.GetServiceRequestSQL();
Model = DBHelper.ToList(dt);
return Model;
}
catch (Exception ex)
{
ErrorHandler.WriteError(ex.Message);
return null;
}
}
-------------------------------------------------------------------------------------
Result.............
[
{
"id": "",
"contactListId": "65bdb317-b4d7-4319",
"data": null,
"callable": "true",
"phoneNumberStatus": "1"
},
{
"id": "",
"contactListId": "65bdb317-b4d7-4319",
"data": null,
"callable": "true",
"phoneNumberStatus": "1"
}
]
TIA
Sachin SinghPosted Apr 2, 2022, 6:04 AM