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.mzph.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