1

I am trying to use JsonConvert.DeserializeObject to parse a JSON response that I am getting back from a web-service. I have the XSD Schema file for the service, which I ran though the .net converter tool to make a Class. Which everything works perfectly, other than the below field. I get the error in the title. It only happens on Array's of Dates, single dates that have a null return work perfectly fine and are skipped due to turning on the NullValueHandling.Ignore setting. Does anyone know how I could use JSON.NET to skip over theses null dates in the array too? Thanks in advance!

JSON Response: "TheDatesReturned":[null,null,null,null,null,null],

 Private TheDatesReturnedField() As Date

 <System.Xml.Serialization.XmlElementAttribute("TheDatesReturned", DataType:="date")> _
Public Property TheDatesReturned() As Date()
    Get
        Return Me.TheDatesReturnedField
    End Get
    Set(value As Date())
        Me.TheDatesReturnedField= value
    End Set
End Property

NOTE: Changing it to an array of strings fixes it as well, but then they are no longer typed correctly when I actually do get a response.

EDIT:

If any anyone comes across this and is wondering how to get XSD.exe to do it for them. They can add nillable="true" to the field in the XSD file

<xsd:element maxOccurs="6" minOccurs="0" name="TheDatesReturned" type="xsd:date" nillable="true">

This will then generate the Class with this, which should take care of the issue.

Private TheDatesReturnedField() As System.Nullable(Of Date)   
tryonlinux
  • 118
  • 1
  • 11
  • 4
    Possibly because DateTime is not a nullable type? Try using `DateTime?` as the type. – Sam Feb 11 '16 at 20:24
  • Possible duplicate of [DateTime "null" value](http://stackoverflow.com/questions/221732/datetime-null-value) – Gabe Feb 11 '16 at 20:26
  • @Sam Thanks that did it for me. Too bad XSD.exe can't used DateTime? as the default type. Not sure how I can mark your comment as an answer but that did it for me. Thank you! – tryonlinux Feb 11 '16 at 20:41
  • I'll post as an answer. – Sam Feb 11 '16 at 20:59

1 Answers1

1

Possibly because DateTime is not a nullable type? Try using DateTime? as the type.

Sam
  • 9,933
  • 12
  • 68
  • 104