Daniel Santos
Daniel Santos

Reputation: 15928

What is the best way to declare JSON structures like this in C#?

im porting a solution to C# code, that contains a piece of code like this.

public object data = 
{

    Background:
    [
        [1.45,2.85, 42.6,2.85, 42.6,44, 1.45,44]
    ]
    ,
    Wall1:
    [
        [8.35,7.05, 116.3,7.05, 116.3,938.8, 8.35,938.8]
    ]
    ,
    Wall2:
    [
        [0,0, 141,0, 141,455, 0,455]
    ]
    ,
    Floor:
    [
        [0.35,8.4, 1075.05,8.4, 1075.05,48.15, 0.35,48.15]
    ]
    .... a lot of other declaration..

What is the best way do declare this kind of object in c#??

Thanks..

Upvotes: 0

Views: 124

Answers (1)

Can Poyrazoğlu
Can Poyrazoğlu

Reputation: 34790

IDictionary<string, object> would fit your solution if the contents are not known in advance. If direct structure is known, you can create a strongly-typed class for it, which will be easier to maintain and less-error prone, with the benefit of performance gain.

Upvotes: 3

Related Questions