Convert JSON string to C# string array

Connie DeCinko picture Connie DeCinko · Feb 10, 2013 · Viewed 18.8k times · Source

Using JSON.Stringify I pass the following string inside another Stringify object.

[
    [
        "I-000-4310-000",
        "Convention Registration",
        "59.99"
    ],
    [
        "I-000-4311-000",
        "Convention Breakout",
        "39.99"
    ]
]

In my C# web service I need to split the string apart into a string array that looks like this:

 string[, ,] GLCodes = new string[,,] 
 { 
    {
        { "I-000-4310-000", "Convention Registration", "59.99" }, 
        { "I-000-4311-000", "Convention Breakout", "9.99" }
    } 
 };

What is the simplest way to do this?

Answer

Connie Hilarides picture Connie Hilarides · Feb 26, 2013

Using Json.NET you can deserialize that list with this

string[][] strings = JsonConvert.DeserializeObject<string[][]>(jsonData);

Hope this helps!