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

前端 未结 21 2804
粉色の甜心
粉色の甜心 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:08

    For those searching the internet and stumbling upon this post, I wrote a blog post on how to use the JavaScriptSerializer class.

    Read more... http://procbits.com/2011/04/21/quick-json-serializationdeserialization-in-c/

    Here is an example:

    var json = "{\"id\":\"13\", \"value\": true}";
    var jss = new JavaScriptSerializer();
    var table = jss.Deserialize(json);
    Console.WriteLine(table["id"]);
    Console.WriteLine(table["value"]);
    

提交回复
热议问题