Smeth
Smeth

Reputation: 25

C# How can i deserialize json DATAS array in the simple struct?

{
    "ASD": { "CONNECTIONS": 1, "DATAS": [0, 0, 0] },
    "Something": {
        "PITCH": 77,
    }
}    

data = JsonConvert.DeserializeObject<DATA>(text);

public class DATA
{
    public struct ASD
    {
            public float CONNECTIONS;
            public float[] DATAS; //?? This is every time is null
    }

    public struct Something
    {
        public float PITCH;
   }
}

enter image description here

Upvotes: 1

Views: 114

Answers (1)

Jamiec
Jamiec

Reputation: 136154

It is not enough to simply define the structs you want to use. The object ASD must have properties typed as these structs. (Note the 0 references hint above the definitions in your screenshot!)

public class DATA
{
    public ASD ASD{get;set;}
    public Something Something {get;set;}
}

public struct ASD
{
    public float CONNECTIONS;
    public float[] DATAS; //?? This is every time is null (not any more it wont be!)
}

public struct Something
{
    public float PITCH;
}

Live example of it working: https://dotnetfiddle.net/wgI5zR

Upvotes: 4

Related Questions