相关疑难解决方法(0)

.Net Core 3.0 TimeSpan 反序列化错误 - 在 .Net 5.0 中修复

我正在使用 .Net Core 3.0 并有以下字符串,我需要用 Newtonsoft.Json 反序列化:

{
    "userId": null,
    "accessToken": null,
    "refreshToken": null,
    "sessionId": null,
    "cookieExpireTimeSpan": {
        "ticks": 0,
        "days": 0,
        "hours": 0,
        "milliseconds": 0,
        "minutes": 0,
        "seconds": 0,
        "totalDays": 0,
        "totalHours": 0,
        "totalMilliseconds": 0,
        "totalMinutes": 0,
        "totalSeconds": 0
    },
    "claims": null,
    "success": false,
    "errors": [
        {
            "code": "Forbidden",
            "description": "Invalid username unknown!"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

并遇到以下错误:

   Newtonsoft.Json.JsonSerializationException : Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.TimeSpan' because the type requires a JSON primitive value (e.g. …
Run Code Online (Sandbox Code Playgroud)

timespan json.net json-deserialization .net-core .net-core-3.0

16
推荐指数
2
解决办法
1万
查看次数