-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?

2
  • 1
    That isn't valid JSON, you need to surround it with [...] for example. Commented Apr 18, 2019 at 16:20
  • Take a look here for JSON formatting for arrays stackoverflow.com/questions/11197818 Commented Apr 18, 2019 at 16:22

1 Answer 1

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}]");
Sign up to request clarification or add additional context in comments.

2 Comments

Its working. But what u wrote and what i wrote is the same.
How is it the same?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.