I generate json using the Newtonsoft.Json; library Newtonsoft.Json;
The answer should be of the type {Command:"CommandName", Data:{"Param1":1,"Param2":2}}
There will always be a Command and Data structure, but the contents are different. But the structure of Data is also different.
How to organize the structure, so that if Command = "command 1", it was generated according to one scenario, and if the other is different?
For example:
{Command:"FilesList", Data:{"Files":["file1","file2","file3","file4"]}} {Command:"UserInfo", Data:{"UserId":1, "UserName": "Roman" ....}} Ie, I will create the appropriate classes FilesList, UserInfo, and here is how to pass the "undefined" class? or do overload method? Can somehow describe the base class, where will be Command and Data and somehow in Data to thrust the corresponding classes and then generate json? So I create json.
string data = JsonConvert.SerializeObject(DataInfo, Formatting.Indented);