JIL .NET JSON Deserialization exception
Asked Answered
L

2

5

I run simple deserialization into own type Event with :

JSON.Deserialize<Event>(text);

with exception:

An exception of type 'Jil.DeserializationException' occurred in Jil.dll but was not handled in user code.
Additional information: Expected character: '\'

Newtonsoft's JSON deserialization works well on the same json, also JSONLint confirmed JSON is valid. Any clues here ? I tried passing in string, as well as using using(StringReader) as is suggested on JIL's github page.

Lederer answered 9/4, 2015 at 10:37 Comment(0)
C
8

Without seeing the JSON-String, you try to deserialize i am not sure about this, but eventually the deserializer expects the date(time) that you're trying to deserialize to be in another format (I guess you're trying to deserialize a datetime-field).

It seems that JIL assumes, that datetimes are delivered as 'NewtosoftDateTime', but you are delivering another format. See https://github.com/kevin-montrose/Jil/blob/master/Jil/Deserialize/InlineDeserializer.cs#L667 for detailed infos, how jil assumes your date is formatted.

You can change the expected formatting via Options. See more here: https://github.com/kevin-montrose/Jil/blob/master/Jil/Options.cs

Clodhopping answered 9/4, 2015 at 11:6 Comment(1)
you are correct, date was the issue here, choosing correct option solved the problemLederer
T
0

DateTime in .Net has a kind attached. Which can be one of three things Local, Utc or Unspecified. I believe Jil should behave differently for ISO8601 format.

Currently doing:

JSON.Serialize(DateTime.Now, new Options(dateFormat: DateTimeFormat.ISO8601))

returns:

"2014-10-09T012:25:08.5660994"

Tuberculate answered 3/4 at 5:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.