1

I'm trying to serialize a nested dictionary of int arrays (<int[], <int[], int>>) with Json.net but when I run it through the serializer:

string dumpFile = JsonConvert.SerializeObject(chordChain, Formatting.Indented);

I get this:

{
  "Int32[] Array": {
    "Int32[] Array": 10,
    "Int32[] Array": 100,
    "Int32[] Array": 50
  },
  "Int32[] Array": {
    "Int32[] Array": 50,
    "Int32[] Array": 10,
    "Int32[] Array": 100
  },
  "Int32[] Array": {
    "Int32[] Array": 100,
    "Int32[] Array": 50,
    "Int32[] Array": 10
  }
}

What I was expecting was:

{
  "[0, 4, 7]": {
    "[0, 4, 7]": 10,
    "[5, 9, 0]": 100,
    "[7, 11, 2]": 50
  },
  "[5, 9, 0]": {
    "[0, 4, 7]": 50,
    "[5, 9, 0]": 10,
    "[7, 11, 2]": 100
  },
  "[7, 11, 2]": {
    "[0, 4, 7]": 100,
    "[5, 9, 0]": 50,
    "[7, 11, 2]": 10
  }
}

Should Json.net serialize this? If so, what do I need to do?

Thanks.

dbc
  • 104,963
  • 20
  • 228
  • 340
EVG Labs
  • 603
  • 5
  • 9
  • I am not sure about the correct behavior but can you try convert the array to list and try that? – Ali Baig Jan 22 '17 at 20:04
  • That's a [limitation of Json.NET](http://www.newtonsoft.com/json/help/html/SerializationGuide.htm#Dictionarys). For workarounds see [Serialize Dictionary<,> as array in Json.NET](https://stackoverflow.com/questions/18385325/serialize-dictionary-as-array-in-json-net/18386620#18386620) and [How can I serialize/deserialize a dictionary with custom keys using Json.Net?](https://stackoverflow.com/questions/24681873). – dbc Jan 22 '17 at 20:14
  • Thanks, that's what I was figuring. I'll take a look at those links. – EVG Labs Jan 22 '17 at 23:11

0 Answers0