无论我如何尝试,我都会得到以下警告。
严重性 代码 描述 项目 文件 行 抑制状态 警告 CS8600 将 null 字面量或可能为 null 的值转换为非可空类型。
代码如下。
HttpResponseMessage response = await _httpClient.PutAsync(url, requestContent);
string? userResponse = await response.Content.ReadAsStringAsync();
JsonSerializerOptions? options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};
//if (userResponse.Length > 0)
//{
user = JsonSerializer.Deserialize<GetUserById>(userResponse, options);
//}
更新。
我完全删除了if条件,但仍然收到警告。
更新2
按建议添加了空值检查。 但仍然收到该警告。