Without serializing getting data from API response
var apiResponseDetails = authorityApiResponse.Content.ReadAsStringAsync().Result;
"[
{
\"<RoleName>k__BackingField\":\"L5 _Admin _Role\",
\"<RoleType>k__BackingField\":\"565,1\"
}
]"
While Deserializing the same response getting null for RoleName
and RoleType
lstRole = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ChangeRoleNotification>>(Convert.ToString(apiResponseDetails));
Name Value
lstRole Count = 1
[0] {Presentation.Common.ChangeRoleNotification}
RoleName null
RoleType null
[Serializable]
public class ChangeRoleNotification
{
[Newtonsoft.Json.JsonProperty(PropertyName = "RoleName")]
public string RoleName { get; set; }
[Newtonsoft.Json.JsonProperty(PropertyName = "RoleType")]
public string RoleType { get; set; }
}
...
GetUserRolesDetailsRequest getUserRolesDetails = new GetUserRolesDetailsRequest();
getUserRolesDetails.UserID = objUser.UserId;
getUserRolesDetails.RoleName = HttpContext.Current.Session["UserTypeName"].ToString();
getUserRolesDetails.RoleType = HttpContext.Current.Session["RoleType"].ToString();
getUserRolesDetails.RoleID = Convert.ToInt64(HttpContext.Current.Session["RoleID"]);
System.Net.Http.HttpResponseMessage authorityApiResponse = new System.Net.Http.HttpResponseMessage(false ? HttpStatusCode.OK : HttpStatusCode.BadRequest);
System.Net.Http.HttpContent RequestDetails = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(getUserRolesDetails), Encoding.UTF8);
if (!String.IsNullOrEmpty(GetWebConfigKeyValueStatic("FrameworkApiURL")))
{
authorityApiResponse = API.PostAPIAsJson($"{GetWebConfigKeyValueStatic("FrameworkApiURL")}Category/GetCategoryUserRolesDetails", RequestDetails);
if (authorityApiResponse != null && authorityApiResponse.StatusCode == HttpStatusCode.OK && authorityApiResponse.Content.ReadAsStringAsync().Result != null)
{
var apiResponseDetails = authorityApiResponse.Content.ReadAsStringAsync().Result;
lstRole = new List<ChangeRoleNotification>();
lstRole = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ChangeRoleNotification>>(Convert.ToString(apiResponseDetails));
}
}
Since I am working in converting a project into ASP.NET MVC 3-Tier I see a weird k__BackingField
what does it mean?
Updated with Server Side Snippet of Response API:
[Route("Category/GetCategoryUserRolesDetails")]
[ActionName("GetCategoryUserRolesDetails")]
[HttpPost]
public HttpResponseMessage GetCategoryUserRolesDetails(CategoryRequestDetails categoryRequestDetails)
{
List<ChangeRoleNotification> response = null;
FrameworkAPIs.Log.LogClass.log.Debug("\nModule Name : Category;\nMethod Name : GetCategoryUserRolesDetails;\n Message :GetCategoryUserRolesDetails method starts ");
string statusCode = String.Empty;
DateTime StartTime = DateTime.Now;
DateTime EndTime = DateTime.Now;
Int64 WebServiceLogID = (new ServiceLogGenerator()).GenerateLog(categoryRequestDetails, "Category", "GetCategoryUserRolesDetails", StartTime, EndTime, "", "", null, 0);
try
{
ManageCategory mangageCategory = new ManageCategory();
if (categoryRequestDetails.UserID > 0)
response = mangageCategory.GetCategoryUserRolesDetails(categoryRequestDetails);
else
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid UserID");
}
catch (Exception ex)
{
FrameworkAPIs.Log.LogClass.log.Error("\nModule Name : Category;\nMethod Name : GetCategoryUserRolesDetails;\nError Message : " + ex.Message + ex.StackTrace + "\n");
(new ServiceLogGenerator()).GenerateLog(null, "", "", StartTime, DateTime.Now, ex.StackTrace + ";\n" + ex.Message, "", null, WebServiceLogID);
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
}
(new ServiceLogGenerator()).GenerateLog(null, "", "", StartTime, DateTime.Now, "", "", response, WebServiceLogID);
FrameworkAPIs.Log.LogClass.log.Debug("\nModule Name : Category;\nMethod Name : GetCategoryUserRolesDetails;\n Message :GetCategoryUserRolesDetails method ends\nResult :" + response);
return Request.CreateResponse<List<ChangeRoleNotification>>(HttpStatusCode.OK, response);
}