问题
I have the following model
public class UserSettings
{
public bool SendEmailAlertsForNewArticlesOrReports { get; set; }
public bool ShowNotificationsInCubeBrowserForArticlesAndReports { get; set; }
}
I serialize it like this
string sUserSettings = JsonConvert.SerializeObject(userSettings);
It stores this in the backend
"{\"SendEmailAlertsForNewArticlesOrReports\":false,\"ShowNotificationsInCubeBrowserForArticlesAndReports\":true}"
When I am trying to deserialize it like this
UserSettings userSettings = JsonConvert.DeserializeObject<UserSettings>(result);
The value of result is
"{\"SendEmailAlertsForNewArticlesOrReports\":false,\"ShowNotificationsInCubeBrowserForArticlesAndReports\":true}"
I get this error
Could not cast or convert from System.String to RystadEnergy.Web.Models.Rystad.UserSettings
Anyone knows what am I missing?
来源:https://stackoverflow.com/questions/50768814/jsonconvert-deserializeobject-error-in-c-sharp