Код: Выделить всё
[{"command":"addItem","payload":{"id":1,"catId":1,"sId":1,"price":1.2,"quantity":1}}]
Код: Выделить всё
public class Input
{
public string Command { get; set; }
public object Payload { get; set; }
}
Код: Выделить всё
List command = JsonSerializer.Deserialize(commandLine);
Кроме того, я читаю входной файл с помощью следующего кода:
Код: Выделить всё
string inputFilePath = Path.Combine(Directory.GetCurrentDirectory(), "input.txt");
if (!File.Exists(inputFilePath))
{
Console.WriteLine($"Not found: {inputFilePath}");
return;
}
string jsonContent = await File.ReadAllTextAsync(inputFilePath);
List commands = JsonSerializer.Deserialize
Подробнее здесь: [url]https://stackoverflow.com/questions/79044892/issues-with-json-deserialization-and-console-input-in-a-c-sharp-console-applicat[/url]