0

I'm using a custom API and part of the response is explanation of the results which looks like this:

"explain": {
    "": "qwer",
    "": "asd"
}

As you can see the keys are empty so while trying to deserialize it to Dictionary using Newtonsoft.Json I get a dictionary containing only 1 value as each one overrides the previous.

dbc
  • 104,963
  • 20
  • 228
  • 340
AOY
  • 355
  • 3
  • 22
  • 1
    Where did this custom API come from? Why would field names be blank? How would you know what field value is referencing? The order in which they appear? – gravity Aug 02 '17 at 12:52
  • Either deserialize it using one of the other values as key, or deserialize it to a list of Tuple, or KeyValuePair or something. – ZiNNED Aug 02 '17 at 12:53
  • I'm using solr api and I really don't know why do the return data this way. It is sorted by the order in which the searched documents are returned as the explanation is for the search – AOY Aug 02 '17 at 12:54
  • 1
    Json.NET has no problem deserializing an empty dictionary key. The real problem is dealing with the key duplication. For that, see [How to deserialize JSON with duplicate property names in the same object](https://stackoverflow.com/q/20714160). Note that duplicated keys are not recommended, according to the [JSON RFC](https://tools.ietf.org/html/rfc7159#section-4): *When the names within an object are not unique, the behavior of software that receives such an object is unpredictable. Many implementations report the last name/value pair only...* – dbc Aug 02 '17 at 18:02

0 Answers0