Код: Выделить всё
Startup.csКод: Выделить всё
public void ConfigureServices(IServiceCollection services)
{
// [...]
services.AddControllers().AddNewtonsoftJson();
// [...]
}
Код: Выделить всё
Data.csКод: Выделить всё
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace MyNS
{
[JsonObject]
public class MyData
{
[JsonProperty("query", Required=Required.Always)]
public Query Query { get; set; }
[JsonProperty("limit")]
public int Limit { get; set; }
}
public class Query
{
[JsonProperty("props", Required=Required.Always)]
public List Props { get; set; }
}
public class Prop
{
// Allowed values should be only ("key1" and "key2"). Other strings or types should fail validation
[JsonProperty("key", Required = Required.Always)]
public string Key { get; set; }
[JsonProperty("value", Required = Required.Always)]
public string Value { get; set; }
}
}
Код: Выделить всё
MyController.csКод: Выделить всё
// [...]
[Route("test")]
[HttpPost]
public async Task Test(MyData data)
{
return Json(data);
}
// [...]
Подробнее здесь: https://stackoverflow.com/questions/647 ... r-a-proper