@H_502_2@这两天在整理.net中各种类型与Json的转换方法,后有同事推荐了Json.net,于是试着研究了一下,并做了简单的测试。
@H_502_2@总的来说,这是一个不错的辅助工具,这一节给出Json.net中常用类型序列化为Json字符串的用法,所有测试代码均为控制台应用程序。
@H_502_2@1)序列化集合
<strong> </strong>/************* 序列化集合 **************/ static void Serialize_a_Collection() { //List赋值方法-01 List<string> videoGames = new List<string>(); videoGames.Add("Starcraft"); videoGames.Add("Halo"); videoGames.Add("Legend of Zelda"); //List赋值方法-02 //List<string> videoGames = new List<string> //{ // "Starcraft",// "Halo",// "Legend of Zelda" //}; //序列化 string json = JsonConvert.SerializeObject(videoGames); //序列化后的json数据格式 // ["Starcraft","Halo","Legend of Zelda"] Console.WriteLine(json); }@H_403_19@ 执行结果: