JsonConvert DeserializeObject error in c#

柔情痞子 提交于 2020-01-16 15:43:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!