Json Format for a TimeSpan that can be bound using Microsoft.Extensions.Configuration

mon*_*nty 9 .net-core asp.net-core-2.0

In a project I need to configure some third party library via the Micorosoft.Extensions.Configuration.

The library gives an options class and I used the configurationSection.Bind(optionsClassInstance) method to bind the values.

It works well except the nested TimeSpan value. I can't figure out what the json structure of a timespan is so it could be bound.

There are no errors. The values from the json are simply not bound.

So far I just used "timespan": { "Days": 0, "Hours": 1, "Minutes": 0 }


多亏了答案,我成功地测试了给定值和给定结果:

1.02:03:04.567 = 1天,2小时,3分钟,4秒,567毫秒

1.02:03:04 = 1天,2小时,3分钟,4秒,0毫秒

02:03:04 = 0天,2小时,3分钟,4秒,0毫秒

03:04 = 0天,3小时,4分钟,0秒,0毫秒

04 = 4天0小时0分钟0秒0毫秒

bri*_*bri 12

.net核心中的时间跨度格式为D.HH:mm:nn(因此“ 1.02:03:04”为1天2小时3分4秒)。

javascript将无法读取该信息(出于这个原因,我们将自定义JsonConverter用于时间跨度对象),但是.Net可以。

{"timespan":"1.02:03:04"}
Run Code Online (Sandbox Code Playgroud)