I am receiving json object in string format. Now i have my model class like this in .netcore
public class AgentSessions
{
// public BsonObjectId _id {get; set;}
public string[] socketID {get; set;}
public string agent_id {get; set;}
public string nsp {get; set;}
public string createdDate {get; set;}
public string nickname {get; set;}
public string email {get; set;}
public ExpandoObject rooms {get; set;}
public int chatCount {get; set;}
public string type{get; set;}
public string[] location {get; set;}
public int visitorCount {get; set;}
public string role {get; set;}
public Boolean acceptingChats {get; set;}
public string state {get; set;}
public ExpandoObject[] idlePeriod {get; set;}
public string image {get; set;}
public ExpandoObject locationCount{get; set;}
public ExpandoObject callingState{get; set;}
public ExpandoObject permissions{get; set;}
public dynamic groups {get; set;}
public dynamic teams {get; set;}
public dynamic isOwner {get; set;}
public Boolean updated {get; set;}
public int concurrentChatLimit{get; set;}
public ExpandoObject conversationState{get; set;}
public string id{get; set;}
public Boolean inactive{get; set;}
public string lastTouchedTime{get; set;}
public DateTime? expiry{get; set;}
public DateTime endingDate{get; set;}
}
Now i have to convert that json object(string) into my defined class type. How can i do that?
stringify data object that i am receiving
"session":{"_id":"5e2acd287ce5f349008348f5","socketID":[],"agent_id":"5c41ade033aa87307ca9831f","nsp":"/localhost.com","createdDate":"2020-01-24T10:55:36.293Z","nickname":"Nickname Changing","email":"[email protected]","rooms":{},"chatCount":0,"type":"Agents","location":[],"visitorCount":0,"role":"admin","acceptingChats":true,"state":"ACTIVE","idlePeriod":[],"image":"https://elasticbeanstalk-us-west-1-021594099427.s3.amazonaws.com/userUploads%2Fhrm.sbtjapan.com%2Fsaadisheikh9705%40sbtjapan.com%2Fpp%2F1546264191938.jpg","locationCount":{},"callingState":{"socketid":"","state":false,"agent":""},"permissions":{"tickets":{"enabled":true,"canMerge":true,"canCreate":true,"canViewLog":true,"canGroup":true,"allowCC":true,"allowBCC":true,"canView":"all","canAssignAgent":true,"canAssignGroup":true,"canAddNote":true,"canAddTag":true,"canAddTask":true,"canChangeState":true,"canExport":true,"canSetPriority":true,"canSnooze":true,"canAddGroupAdmins":true},"chats":{"enabled":true,"allowEmoji":true,"allowAttachments":true,"allowVoicenotes":true,"allowCalling":true,"allowAddAsFaq":true,"allowChatTransfer":true,"allowTypingStatus":true,"canView":"all","canChat":true},"agents":{"enabled":true,"canCreate":true,"canEdit":true,"canChat":true,"canCall":true,"canViewStats":true,"canChangeOwnPassword":true,"canChangeOthersPassword":true},"settings":{"enabled":true,"automatedResponses":{"enabled":true},"rolesAndPermissions":{"enabled":true,"canView":["admin","supervisor","agent","TEst"],"canAddRole":true,"canModifyOwn":true,"canModifyOther":true,"canDeleteRole":true},"formDesigner":{"enabled":true},"ticketManagement":{"enabled":true},"chatTimeouts":{"enabled":true},"callSettings":{"enabled":true},"contactSettings":{"enabled":true},"chatWindowSettings":{"enabled":true},"chatAssistant":{"enabled":true},"webhooks":{"enabled":true},"integerations":{"enabled":true},"knowledgeBase":{"enabled":true},"widgetMarketing":{"enabled":true}},"dashboard":{"enabled":true},"visitors":{"enabled":true},"analytics":{"enabled":true,"visitors":true,"canView":"all","chats":true,"agents":true,"tickets":true},"crm":{"enabled":true},"chatbot":{"enabled":true},"installation":{"enabled":true},"updatedOn":"2020-01-07T11:50:43.690Z"},"groups":["Congo1"],"teams":[],"isOwner":false,"updated":true,"concurrentChatLimit":2,"conversationState":false,"id":"5e2acd287ce5f349008348f5","inactive":false,"lastTouchedTime":"2020-01-24T10:55:37.344Z","endingDate":"2020-01-24T10:55:56.980Z"}
And another question is that what happened if any value will not be there in my json object(string format) ?
stringifyis how Javascript converts an object to JSON. It has nothing to do with the JSON content itself. What you posted is simply a JSON string that needs to be parsed using eg Json.NET or System.Text.JSONstringify object. What you posted is just a JSON string. You can deserialize it with JSON.NET