Resolved how to deserialize json without name

Samuraix

Member
Joined
Aug 9, 2021
Messages
9
Programming Experience
Beginner
How do I deserialize this json in C# ?
C#:
{
    "data": {
        "861": [
            3218
        ],
        "862": [
            3219
        ],
        "863": [
            3220
        ],
        "864": [
            3221
        ],
        "1631": [
            5993
        ],
        "1632": [
            5994
        ],
        "1633": [
            5995
        ],
        "1634": [
            5996
        ],
        "1635": [
            5997
        ],
        "1636": [
            5998
        ]
    },
    "range": {
        "total": 1938,
        "from": 1,
        "to": 10
    }
}
 
Why don't you tell us exactly what you want to get out of the JSON string? Are you hoping to get some kind of object back? Or is there just a specific value you want to pull out and you don't really care about the rest? Or something between those two extremes?
 
This is an English language forum. Please translate.
 
Okay, so presumably you want to get all the data from the JSON string and flatten it to column name and row values. I know of very few database table designs where column names are numbers. How do you plan to deal with the "861" column with a row value of: 3281?
 
And how were we supposed to figure that out just based on your post #1?

I think you need to give a more detailed description of exactly what you are trying to do.
 
I find the solution:

C#:
                        dynamic itemJson = Newtonsoft.Json.JsonConvert.DeserializeObject(sRetorno);
                        var rows = itemJson.data;
                        
                        foreach (dynamic row in rows)
                        {
                            Console.WriteLine("idProduct: " + row.Name);

                            foreach ( dynamic rowitem in row )
                            {

                                foreach( dynamic rowSKU in rowitem)
                                {
                                    Console.WriteLine(rowSKU);
                                }

                            }

                        }

Thanks for everybody...
 
Last edited by a moderator:
I'm glad that you found a solution for your problem. I'm wondering though how we were supposed to figure out that you were only interested in the "data" section of the JSON string, and completely throwing away the "range" section, and that the values within the "data" section are product IDs and SKUs.
 
Back
Top Bottom