-1

i am using Newtonsoft.Json and trying to deserialize an array of arrays Json string into C# object i created.

This is the json string -

[4615,4618,4619,4626,4615,4626,4631,4636,4637],[4615,4618,4619,4626,4615,4626,4631,4636,4637],[4615,4618,4619,4626,4615,4626,4631,4636,4637]

This is my object model -

  public class NumberMatrix
    {
        public List<int> NumberIDs { get; set; }

        public NumberMatrix()
        {
            this.NumberIDs = new List<int>();
        }
    }

This is how i try to convert -

var numbers = HttpContext.Current.Request.Params["Numbers"];
var numberIDsMatrix = JsonConvert.DeserializeObject<List<NumberMatrix>>(numbers);

i tried to deserialize the json in few ways, and got different errors. is it possible to deserialize this json string? how?

doron hine
  • 13
  • 7
  • 1
    That isn't valid JSON, you need to surround it with `[...]` for example. – DavidG Apr 18 '19 at 16:20
  • Take a look here for JSON formatting for arrays [stackoverflow.com/questions/11197818](https://stackoverflow.com/questions/11197818/how-do-i-make-a-json-object-with-multiple-arrays) – melkisadek Apr 18 '19 at 16:22

1 Answers1

0

That isn't valid JSON, you need to surround it with [...] for example. You could do this:

var result = JsonConvert.DeserializeObject<List<List<int>>>($"[{numbers}]");
DavidG
  • 113,891
  • 12
  • 217
  • 223