Deserialize a Dictionary

April 6, 2024 ยท View on GitHub

This sample deserializes JSON into a dictionary.

var json = """
    {
      'href': '/account/login.aspx',
      'target': '_blank'
    }
    """;

var htmlAttributes = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);

Console.WriteLine(htmlAttributes["href"]);
// /account/login.aspx

Console.WriteLine(htmlAttributes["target"]);
// _blank

snippet source | anchor