1

I am trying to deserialize a field:

"presenters":[{...},{...}]

but some of the rows come back with only:

"presenters":""

When the serializer gets to the row with that empty string I get:

Error converting value "" to type 'System.Collections.Generic.List`1[DataPrototype.Model.Presenter]'.

Am I right in thinking that I need a JsonConverter that will change the empty string into an empty List?

karl.r
  • 961
  • 1
  • 11
  • 28
  • 3
    Well, it would be better if you simply didn't get schizophrenic data to begin with. – Etienne de Martel Jan 01 '11 at 00:21
  • possible duplicate of [Deserializing JSON when sometimes array and sometimes object](http://stackoverflow.com/questions/5224697/deserializing-json-when-sometimes-array-and-sometimes-object) – Robert MacLean Aug 03 '12 at 12:27

1 Answers1

4

Yes.

Inside the JsonConverter test the token type from the JsonReader.

If it is a string then return null.

If it is the start of an array then use the JsonReader and JsonSerializer passed to the converter method to deserialize the array.

James Newton-King
  • 48,174
  • 24
  • 109
  • 130