Skip to content
Loading
  • Mario Scheeren
    0
    What does your JSON look like when yout object has been converted?
     
    JsonConvert.SerializeObject(value)
     
    Maybe adding "{ \"menu\": [" + myJSON + "]}" can do the trick.
     
    THe Problem is converting an IEnumerable does not automatically resuklt in an array if only one element within. So you need to Force it to be an Array!
    0
  • Adalat  Khan
    0
    Dear Madan Sorab,
    It converts object to json and reconverts to object but i want to serialize the query result into json and Deserialize the query result but when i deserialize it gives me error as menshioned above. Following is my Query Result:
     
    IEnumerable menuDetails = (from userRights in dbContext.UserRightsDetails
    join mainMenu in dbContext.MainMenu
    on userRights.MainMenuId equals mainMenu.MainMenuId
    join subMenu in dbContext.SubMenu
    on userRights.SubMenuId equals subMenu.SubMenuId
    join uRole in dbContext.UserRoles
    on userRights.RoleId equals uRole.RoleId
    where userRights.RoleId == userRoleId
    select new MenuModels
    {
    MainMenuId = mainMenu.MainMenuId,
    MainMenuName = mainMenu.MainMenuName,
    SubMenuId = subMenu.SubMenuId,
    SubMenuName = subMenu.SubMenuName,
    Controller = subMenu.Controller,
    Action = subMenu.Action,
    RoleId = uRole.RoleId,
    RoleName = uRole.RoleName
    }).ToList();
    //Pass the Model data to Session
    HttpContext.Session.SetSessionModelData("MenuMaster", menuDetails);
     
     
    The Serialization has successful but when i used the follwowing deserialize code then it gives me error:
     
    ViewBag.LoginSession = HttpContext.Session.GetSessionModelData("MenuMaster");
    0
  • Madan Shekar
    0
    1. return value == null ? default(T) : JsonConvert.DeserializeObject(value);  
    try this one T in the sense your collection and value in the sense data(data which u are going to deserialize)
    0
  • Sagar Malde
    0
    Check if you are re-assigning session key MenuMaster somewhere  in your code.
     
    Also provide json which you are setting and also what you are retreving from session.
    0