【发布时间】:2021-04-06 13:52:57
【问题描述】:
我有一个具有以下结构/类的控制器:
// model
public class Result
{
public string Document { get; set; } = "";
public int[,] Segments { get; set; } = new int[,] { };
}
// controller
public class SearchController : ControllerBase {
[HttpGet]
[Route("/api/v1/[controller]")]
[Produces("application/json")]
public IActionResult Search(//metadata list)
{
try {
Result result = <service-call-returning Result object>;
return Ok(result);
} catch (Exception e) {
return BadRequest("bad");
}
}
}
似乎无法序列化 Result 对象,出现以下异常:
失败:Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
执行请求时发生未处理的异常。
System.NotSupportedException:不支持类型“System.Int32[,]”。
在 System.Text.Json.ThrowHelper.ThrowNotSupportedException_SerializationNotSupported(Type propertyType)
在 System.Text.Json.Serialization.Converters.IEnumerableConverterFactory.CreateConverter(类型 typeToConvert,JsonSerializerOptions 选项)
在 System.Text.Json.Serialization.JsonConverterFactory.GetConverterInternal(类型 typeToConvert,JsonSerializerOptions 选项)
在 System.Text.Json.JsonSerializerOptions.GetConverter(类型 typeToConvert)
如何使用(字符串,多维数组)序列化对象?另外我有一个期望结果的反应应用程序,字符串也将被序列化(有 \n\n \r ....),是客户端应用程序反序列化它的工作还是我需要找到一种返回非序列化 JSON 对象的方法?
【问题讨论】:
-
您是否有现有的格式可以匹配(请编辑)?锯齿状数组可能是这里的解决方案
标签: c# asp.net-core asp.net5