How to decode a JSON string using C#?

后端 未结 2 1667
旧时难觅i
旧时难觅i 2020-11-30 08:19

I\'m looking for an example code/lib to decode a JSON string using C#.

To encode I can do this:

var data = new Dictionary(); 
d         


        
2条回答
  •  春和景丽
    2020-11-30 08:58

    You can do this:

    var data = new Dictionary();
    data.Add("foo", "baa"); 
    
    JavaScriptSerializer ser = new JavaScriptSerializer();
    var JSONString = ser.Serialize(data); //JSON encoded
    
    var JSONObj = ser.Deserialize>(JSONString); //JSON decoded
    Console.Write(JSONObj["foo"]); //prints: baa
    

提交回复
热议问题