Я использовал этот метод
Код: Выделить всё
private static async Task HandleFormAsync(HttpContext httpContext, ModelBindingContext bindingContext)
{
var form = await httpContext.Request.ReadFormAsync();
string jsonString = $"{{{string.Join(",", form.Select(x => $"\"{x.Key}\" : \"{x.Value}\""))}}}";
try
{
var what = ProcessArray(jsonString);
PagedRequest pagedRequest = what?.ToObject
();
if (string.IsNullOrEmpty(jsonString))
{
bindingContext.Result = ModelBindingResult.Failed();
return;
}
// Convert the form value to the target model type
var model = JsonConvert.DeserializeObject(jsonString, bindingContext.ModelType);
bindingContext.Result = ModelBindingResult.Success(model);
return;
}
catch (JsonException)
{
// Deserialization failed, possibly due to invalid JSON
bindingContext.Result = ModelBindingResult.Failed();
return;
}
}
Например, json будет таким:
Код: Выделить всё
{"filterList[0].filterType" : "contains","filterList[0].filterDataType" : "string","filterList[0].field" : "firstName","filterList[0].filterValue" : "bob","filterList[1].filterType" : "starts_with","filterList[1].filterDataType" : "string","filterList[1].field" : "lastName","filterList[1].filterValue" : "dylan","pageSize" : "15","pageNumber" : "1"}
Я пробовал это
Код: Выделить всё
["](?\w+\[\d+\])\.(?
\w+)["]\s*[:]\s*["](?.*?)["][,}]
Только значения, выделенные жирным шрифтом.
{"filterList[0] .filterType": содержит,"filterList[0].filterDataType":"string","filterList[0].field" : "firstName","filterList[0].filterValue" : "bob" ,"filterList[1].filterType" : "starts_with","filterList[1].filterDataType" : "string","filterList[1].field" : "lastName","filterList[1].filterValue" : " Дилан"
Есть идеи, как это сделать?
Подробнее здесь: https://stackoverflow.com/questions/786 ... -in-dotnet