Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"Obj1": {
      0: 17, 
      1: 23,
      2: 23, 
      3: 24,
      4: 25,
      5: 56,
      6: 65
    },
    "Obj2": {0: 177,..,6: 65},      
    "Obj3": {0: 177,..,6: 65},
    "Obj4": {0: 177,..,6: 65}

Can anyone help me the best way to generate the Modal class? I am using POCO reverse generation method to fetch the data. So mostly I will be using LINQ to map into Modal class.

What I have tried:

public class Week
    {
        public int?[] Obj1= new int?[6];

        public int?[] Obj2= new int?[6];

        public int?[] Obj3= new int?[6];

        public int?[] Obj4= new int?[6];
    }
Posted
Updated 6-Oct-17 21:54pm

1 solution

You can use this service for generating classes from valid JSON data: JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^]

Your JSON data is invalid. Looking at your class, it should be something like:
{"Obj1": [
      17, 
      23,
      23, 
      24,
      25,
      56,
      65
    ],
    "Obj2": [177,...,65],
    "Obj3": [177,...,65],
    "Obj4": [177,...,65]
}

You can read more here: Working with JSON in C# & VB[^]
 
Share this answer
 
Comments
Member 11725507 7-Oct-17 5:03am    
Thanks for the comments. Yes, Its a invalid JSON. Is it possible to atleast create like below, "Obj1": {
"0": 17,
"1": 23,
"2": 23,
"3": 24,
"4": 25,
"5": 56,
"6": 65
}
Graeme_Grant 7-Oct-17 7:00am    
Yes you can, however properties must be valid names. "0" is invalid however, as in the linked article, you can use JsonProperty to map to a valid property name. Something like:

[JsonProperty("0")]
public string Field0 { get; set; }
Member 11725507 7-Oct-17 7:38am    
Thanks a lot for the solution
Graeme_Grant 7-Oct-17 9:24am    
You are welcome... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900