Bop It Freak
Bop It Freak

Reputation: 37

How do i convert this JSON object into C# code?

I'm trying to convert a JSON object from JavaScript into C#. I want to be able to access it like you would in normal JavaScript, like this: letters.property[arrayindex].

I tried some of those online converters, which gave me the class, but some of the properties of the object are invalid; I basically have one property for every letter of the alphabet, and some of the punctuation characters, like the semicolon, which C# won't let me use as an object property.

Here is the JSON object I want to convert:

 {
            "-": [

        ["0", "0", "0", "0", "0", "0", "0", "0"],
        ["0", "0", "0", "0", "0", "0", "0", "0"],
        ["0", "0", "1", "1", "1", "1", "0", "0"],
        ["0", "0", "1", "1", "1", "1", "0", "0"],
        ["0", "0", "1", "1", "1", "1", "0", "0"],
        ["0", "0", "0", "0", "0", "0", "0", "0"],
        ["0", "0", "0", "0", "0", "0", "0", "0"],
        ["0", "0", "0", "0", "0", "0", "0", "0"]



   ],
}

That is just one property of the object, there are many after that as well that are similar to this one. How do I convert this?

Upvotes: 0

Views: 100

Answers (1)

JSteward
JSteward

Reputation: 7091

You could try to deserialize to something like this:

var charSet = JsonConvert.DeserializeObject<Dictionary<char, int[][]>>(json);
var valueSet = charSet['-']; 

Upvotes: 3

Related Questions