C# 序列化與反序列化json

與合作伙伴討論問題,說到的c++與c#數據的轉換調用,正好就說到了序列化與反序列化,同樣也可用于不同語言間的調用,做了基礎示例,作以下整理:

 1 using System.Data;
 2 using System.Drawing;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using System.Web.Script.Serialization;
 7 using System.Windows.Forms;
 8 
 9 namespace ConsoleApplication1
10 {
11     public partial class Form9 : Form
12     {
13         public Form9()
14         {
15             InitializeComponent();
16             per();
17         }
18         public string GetPersonInfo()
19         {
20             //實例化Person對象
21             Person per = new Person();
22             per.Name = "lxx";
23             per.Age = 28;
24 
25             //Person對象per序列化為json字符串ss
26             JavaScriptSerializer js = new JavaScriptSerializer();
27             string ss = js.Serialize(per);
28             Console.WriteLine(ss);//運行后ss值為:{"Name":"lxx","Age":28}
29             return ss;
30         }
31 
32         /// <summary>
33         /// json字符串ss反序列化為Person對象
34         /// </summary>
35         /// <returns></returns>
36         public Person per()
37         {
38             JavaScriptSerializer js = new JavaScriptSerializer();
39             Person person = js.Deserialize<Person>(GetPersonInfo());
40             return person;
41         }
42     }
43 
44     /// <summary>
45     /// 定義一個可序列化的實體類(也可以為Structure)
46     /// </summary>
47     [Serializable()]
48     public class Person
49     {
50         public string Name { get; set; }
51         public int Age { get; set; }
52     }
53 }

?

轉載于:https://www.cnblogs.com/lxxhome/p/7027934.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/392416.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392416.shtml
英文地址,請注明出處:http://en.pswp.cn/news/392416.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

學java 的要點_零基礎學Java,掌握Java的基礎要點

對于程序員群體來說&#xff0c;了解一定的技巧會對學習專業技能更有幫助&#xff0c;也更有助于在自己的職業發展中處于有利地位&#xff0c;無限互聯Java培訓專家今天就為大家總結Java程序員入門時需要掌握的基礎要點&#xff1a;掌握靜態方法和屬性靜態方法和屬性用于描述某…

實驗人員考評指標_了解實驗指標

實驗人員考評指標In the first part of my series on experimental design Thinking About Experimental Design, we covered the foundations of an experiment: the goals, the conditions, and the metrics. In this post, we will move away from the initial experimental…

leetcode 188. 買賣股票的最佳時機 IV(dp)

給定一個整數數組 prices &#xff0c;它的第 i 個元素 prices[i] 是一支給定的股票在第 i 天的價格。 設計一個算法來計算你所能獲取的最大利潤。你最多可以完成 k 筆交易。 注意&#xff1a;你不能同時參與多筆交易&#xff08;你必須在再次購買前出售掉之前的股票&#xf…

kotlin編寫后臺_在Kotlin編寫圖書館的提示

kotlin編寫后臺by Adam Arold亞當阿羅德(Adam Arold) 在Kotlin編寫圖書館的提示 (Tips for Writing a Library in Kotlin) Writing a library in Kotlin seems easy but it can get tricky if you want to support multiple platforms. In this article we’ll explore ways f…

1.Swift教程翻譯系列——關于Swift

英文版PDF下載地址http://download.csdn.net/detail/tsingheng/7480427 我本來是做JAVA的。可是有一顆折騰的心&#xff0c;蘋果公布Swift以后就下載了蘋果的開發文檔。啃了幾天。朦朦朧朧的看了個幾乎相同&#xff0c;想靜下心看能不能整個翻譯出來。我英語一般般&#xff0c;…

核心技術java基礎_JAVA核心技術I---JAVA基礎知識(集合set)

一&#xff1a;集合了解(一)確定性&#xff0c;互異性&#xff0c;無序性確定性&#xff1a;對任意對象都能判定其是否屬于某一個集合互異性&#xff1a;集合內每個元素都是無差異的&#xff0c;注意是內容差異無序性&#xff1a;集合內的順序無關(二)集合接口HashSet&#xff…

nba數據庫統計_NBA板塊的價值-從統計學上講

nba數據庫統計The idea is not to block every shot. The idea is to make your opponent believe that you might block every shot. — Bill Russel這個想法不是要阻止每一個鏡頭。 這個想法是讓你的對手相信你可能會阻擋每一個投籃。 —比爾羅素 The block in basketball ha…

leetcode 330. 按要求補齊數組(貪心算法)

給定一個已排序的正整數數組 nums&#xff0c;和一個正整數 n 。從 [1, n] 區間內選取任意個數字補充到 nums 中&#xff0c;使得 [1, n] 區間內的任何數字都可以用 nums 中某幾個數字的和來表示。請輸出滿足上述要求的最少需要補充的數字個數。 示例 1: 輸入: nums [1,3], …

【煉數成金 NOSQL引航 三】 Redis使用場景與案例分析

驗證redis的主從復制&#xff0c;將實驗過程抓圖 復制配置文件 更改slave的端口 和相關master配置 主從復制測試 研究在OAuth中的“一次數”nonce有什么用途&#xff1f;怎樣使用&#xff1f;以此熟悉OAuth的全流程 nonce &#xff0c;一個隨機的混淆字符串&#xff0c;僅僅被…

SQL Server需要監控哪些計數器 ---指尖流淌

http://www.cnblogs.com/zhijianliutang/p/4174697.html轉載于:https://www.cnblogs.com/zengkefu/p/7044095.html

akka 簡介_Akka HTTP路由簡介

akka 簡介by Miguel Lopez由Miguel Lopez Akka HTTP路由簡介 (An introduction to Akka HTTP routing) Akka HTTP’s routing DSL might seem complicated at first, but once you get the hang of it you’ll see how powerful it is.Akka HTTP的路由DSL乍一看似乎很復雜&…

leetcode 1046. 最后一塊石頭的重量(堆)

有一堆石頭&#xff0c;每塊石頭的重量都是正整數。 每一回合&#xff0c;從中選出兩塊 最重的 石頭&#xff0c;然后將它們一起粉碎。假設石頭的重量分別為 x 和 y&#xff0c;且 x < y。那么粉碎的可能結果如下&#xff1a; 如果 x y&#xff0c;那么兩塊石頭都會被完全…

java2d方法_Java SunGraphics2D.fillRect方法代碼示例

import sun.java2d.SunGraphics2D; //導入方法依賴的package包/類/*** Return a non-accelerated BufferedImage of the requested type with the* indicated subimage of the original image located at 0,0 in the new image.* If a bgColor is supplied, composite the orig…

js建立excel表格_建立Excel足球聯賽表格-傳統vs動態數組方法

js建立excel表格介紹 (Introduction) I am going to show you the different ways you can build a football league table in Excel. Some of the methods are old school but others utilise Excel’s new capabilities.我將向您展示在Excel中建立足球聯賽表格的不同方法。 其…

postman+newman生成html報告

作為測試菜鳥,在學習postmannewman的使用過程中真的是頗費周折......沒辦法技術太菜,只能多學習. postman的下載安裝不多言說,下載地址:https://www.getpostman.com/downloads/ newman的安裝過程: 1.首先需要安裝node.js,可以去官網下載,地址:https://nodejs.org/en/#download …

java jdk1.9新特性_JDK1.9-新特性

1. Java平臺級模塊系統該特性使Java9最大的一個特性&#xff0c;Java提供該功能的主要的動機在于&#xff0c;減少內存的開銷&#xff0c;JVM啟動的時候&#xff0c;至少會有30~60MB的內存加載&#xff0c;主要原因是JVM需要加載rt.jar&#xff0c;不管其中的類是否被classload…

如何在10分鐘內讓Redux發揮作用

Hi everyone ??大家好?? For a while now I’ve been hearing my friends and colleagues complaining about how hard it was to get into Redux.一段時間以來&#xff0c;我一直在聽我的朋友和同事抱怨進入Redux有多困難。 I run a freeCodeCamp Study Group in the So…

兩個鏈接合并_如何找到兩個鏈接列表的合并點

兩個鏈接合并了解問題 (Understand the Problem) We are given two singly linked lists and we have to find the point at which they merge.我們給了兩個單鏈表&#xff0c;我們必須找到它們合并的點。 [SLL 1] 1--->3--->5 \ …

安裝veket到移動硬盤NTFS分區

如果你已經看過《手動安裝veket到硬盤》和《簡單的將veket安裝到U盤的方法》兩篇文章并且安裝成功的話&#xff0c;說明不適用本文的安裝環境&#xff0c;就不用往下看了。 《手動安裝veket到硬盤》一文采用grub4dos來引導硬盤上的veket&#xff0c;主要是用來在本機已安裝Wind…

簡書使用小技巧

1、不同字體  在 設置->基礎設置->富文本 模式下可以實現 2、添加圖片&#xff0c;讓文章更生動 3、添加代碼框 &#xff01;注意&#xff1a;設置為Markdown模式后&#xff0c;只對新創建的文章起作用。轉載于:https://www.cnblogs.com/HMJ-29/p/7049540.html