P
P
password222021-09-30 23:43:44
JSON
password22, 2021-09-30 23:43:44

How to convert JSON to C# class?

There is no way I can convert this json data into a class. No matter how much I try, there are always errors.

I can't change this Json, I get the data via api

JSON

{
"blabla": {
    "columns": ["id", "num", "date", "time", "ti", "val"], 
    "data": [
        [30, 45, "2021-05-30", "14:34:34", "FUКЕ", "OLGD"],
        [60, 45, "2020-02-30", "02:21:06", "BEВП", "GASF"]
    ]
}}


C#
I made this code in an online generator and tried to convert it in every possible way, but all to no avail

public class Blabla
{
        public List <string> columns { get; set; }
        public List <List <int>> data { get; set; }
}

public class Root
{
        public Blabla blabla { get; set; }
}

I tried JsonConvert.DeserializeObject, I also tried to convert to JObject and JArray, but I don't understand what's wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-10-01
@vabka

As I understand it, the most important gap in the data array.
If you use System.Text.Json, then it can be typed like this:

[JsonPropertyName("data")]
public JsonElement[][] Data {get; init;}

Well, do not forget to use your head when working with code generators.
You can also go head over heels and write a custom converter for this thing into some DataFrame or DataTable (I don’t remember exactly what this new class for plates is called)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question