Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Deserialize Json dynamically
Message
From
13/02/2021 13:58:28
 
 
To
All
General information
Forum:
C#
Category:
Coding, syntax and commands
Title:
Deserialize Json dynamically
Miscellaneous
Thread ID:
01678204
Message ID:
01678204
Views:
41
Hi, I am working on a tool to edit Json files in a list. The idea is to have sample data that gets loaded into the database on installation. This should work for different tables, for each I need to create a model class.

I have the following code, and I would know how to do that in VFP. Because of string typing in C# I need to use a different approach:
      Users items = JsonConvert.DeserializeObject<Users>(json);
      dgTasks.DataSource = items.users;
So that works well for the Users.json file, but I don't like the idea to write it separately for each table. Is there a way to use Users dynamically, so either I read the class name from the Json file itself or extract it from the json file name, but at least I don't need to have a case statement here?
Like in VFP it would be something like JsonConvert.DeserializeObject<&lctablename>(json);
Christian Isberner
Software Consultant
Reply
Map
View

Click here to load this message in the networking platform