我有我的Api Rest,在某种程度上我验证了一些东西,我使用这行代码将答案返回给客户端计算机:(这是服务器Api Rest代码)
IDictionary<string, string[]> errors = new Dictionary<string, string[]>();
... some validation code...
return Results.ValidationProblem(errors);
之后,在我的客户端程序中,我得到如下响应:(这是客户端程序)
string errorData = await response.Content.ReadAsStringAsync();
我的字符串errorData如下:(如果打印errorData,则该数据在字符串中)
{
"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title":"One or more validation errors occurred.",
"status":400,
"errors":{"Fail to login":["Invalid username or password"]}
}
当我try 将该字符串转换为真实对象时,数据具有类的默认值(空值):(客户端程序)
ResultError? error = System.Text.Json.JsonSerializer.Deserialize<ResultError>(errorData);
ResultError类如下:(客户端程序)
public class ResultError
{
IDictionary<string, string[]> errors = new Dictionary<string, string[]>();
int status = 0;
string title = string.Empty;
string type = string.Empty;
}
如何获得正确的数据?