Я хочу создать общий метод для маскировки свойств пароля внутри документа json. Как установить значение элемента?
private void MaskPassword(string json)
{
var node = JsonNode.Parse(json);
if (node is JsonArray)
{
var arr = JsonSerializer.Deserialize(json);
foreach(var item in arr)
{
MaskPassword(item.ToJsonString());
}
}
else
{
var document = JsonSerializer.Deserialize(json);
foreach (JsonProperty property in document.RootElement.EnumerateObject())
{
if (property.Name.Contains("password", StringComparison.OrdinalIgnoreCase) &&
property.Value.ValueKind == JsonValueKind.String)
{
var strValue = property.Value.GetString();
if (!string.IsNullOrWhiteSpace(strValue))
{
property.Value = new string('*', strValue.Length); //how to set the value here?
}
}
}
json = document.RootElement.ToString();
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... ment-value