How can I deserialize JSON to a simple Dictionary in ASP.NET?

前端 未结 21 2741
粉色の甜心
粉色の甜心 2020-11-21 06:33

I have a simple key/value list in JSON being sent back to ASP.NET via POST. Example:

{ \"key1\": \"value1\", \"key2\": \"value2\"}

21条回答
  •  清酒与你
    2020-11-21 07:03

    Based on comments above try JsonConvert.DeserializeObject>(json)

    var json = @"{""key1"":1,""key2"":""value2"", ""object1"":{""property1"":""value1"",""property2"":[2,3,4,5,6,7]}}";
    var parsedObject = JsonConvert.DeserializeObject>(json);
    

    seems to work even for complex objects and lists.

提交回复
热议问题