Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Deserialize Json dynamically
Message
 
 
À
Tous
Information générale
Forum:
C#
Catégorie:
Code, syntaxe and commandes
Titre:
Deserialize Json dynamically
Divers
Thread ID:
01678204
Message ID:
01678204
Vues:
40
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
Répondre
Fil
Voir

Click here to load this message in the networking platform