Newtonsoft.Json.JsonReaderException:无法将字符串转换为整数

时间:2018-12-05 12:17:16

标签: asp.net json

更改TimeToSendLocation时出现此异常错误 谁能告诉我怎么了,因为我要开枪自杀

    public ReturnObject SetAppSettings(JsonSetting systemSetting)
    {
        try
        {
            Setting updateSetting = model.Settings.FirstOrDefault();

            updateSetting.DelayTolerance = systemSetting.DelayTolerance;
            updateSetting.DashboardRefreshment = systemSetting.DashboardRefreshment;
            updateSetting.NewLocationDistance = systemSetting.NewLocationDistance;
            updateSetting.EndOfWorkTime = systemSetting.EndOfWorkTime.TimeOfDay;
            updateSetting.CheckedInValidation = systemSetting.CheckedInValidation;
            updateSetting.CheckInTolerance = systemSetting.CheckInTolerance;
            updateSetting.AutoSignout = systemSetting.AutoSignout;

            updateSetting.TimeToSendLocation= systemSetting.TimeToSendLocation;

            model.Entry(updateSetting).State = System.Data.Entity.EntityState.Modified;
            model.SaveChanges();

            return new ReturnObject() { Result = true, Message = "Settings Changed Successfully" };

        }

        catch (Exception ex)
        {
            return new ReturnObject() { Result = false, Message = ex.Message };
        }
    }

1 个答案:

答案 0 :(得分:0)

updateSetting的类型为“ Setting”,而systemSetting的类型为“ JSONSetting”。他们有两种不同的类型。这就像将字符串设置为整数。您必须投射/转换它或制作一个新对象。 o ..尝试

 updateSetting.TimeToSendLocation= Convert.ToInt32(systemSetting.TimeToSendLocation);