Receiving NodaTime.LocalTime

102 Views Asked by At

I keep getting the error Cannot convert value to NodaTime.LocalTime, and I can't seem to find anyone else with the problem. I also can't find in the documentation how I can do this.

An example of what I'm trying to send is;

{
   "time": "22:00"
}

Is something wrong with this format? As far as I'm aware, NodaTime.LocalTime is formatted exactly like this. I know a similar problem exists for the date object, but it really doesn't apply to this, as it has no Z at the end of the string. I also tried taking the semi-colon out of the string I send, but that didn't do anything.

Thank you!

1

There are 1 best solutions below

0
Serge On BEST ANSWER

your json is invalid, pls fix it according this example

using NodaTime.Serialization.JsonNet;

var d = new Data { time = NodaTime.LocalTime.Noon };

var json = JsonConvert.SerializeObject(d);

output

{"time":"12:00:00"}

So your json should be

var json =  @"{
   ""time"": ""22:00:00""
}";

Data data = JsonConvert.DeserializeObject<Data>(json);

everything is working properly in this case

class

public class Data
{
    public LocalTime time { get; set; }
}