将对象序列化成XML字符串
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace TestWeb
{
public partial class TestSerializeXml : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void btnSerialize_Click(object sender, EventArgs e)
{
Person p = new Person();
p.Name = "Snow";
p.Age = 41;
string str = this.Serialize(p);
this.TextBox1.Text = str;
} protected void btnDeSerialize_Click(object sender, EventArgs e)
{
Person p = this.Deserialize(this.TextBox1.Text);
Response.Write(p.Name + "*" + p.Age);
} public Person Deserialize(String xml)
{
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(new Person().GetType());
System.IO.StringReader sr = new System.IO.StringReader(xml); Person person = xs.Deserialize(sr) as Person;
sr.Close();
return person;
} private string Serialize(Person person)
{
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(person.GetType()); System.IO.StringWriter sw = new System.IO.StringWriter();
xs.Serialize(sw, person);
String s = sw.ToString();
sw.Close();
return s;
}
}
}
将对象序列化成XML字符串的更多相关文章
- C#对象序列化成XML,以及自定义标签名
C#对象序列化操作: public class XMLHelper { /// <summary> /// 对象序列化成 XML String /// </summary> p ...
- C#将对象序列化成JSON字符串
C#将对象序列化成JSON字符串 public string GetJsonString() { List<Product> products = new List<Product& ...
- XmlSerializer 对象序列化成XML 自定义编码格式(gb2312)
随着面向服务(SOA)的开发方式的兴起,客户端和服务端之间的消息传送,很多采用了XML的格式.但是大家在日常的开发中,应该会有这么种体验,就是组织xml格式的代码太繁琐,这篇随笔也是为了和大家分享下简 ...
- 对象序列化成Json字符串 及 反序列化成对象
一. public static string JsonSerializer<T>(T t) { DataContractJsonSerializer ...
- jackson2.8.4java对象序列化成json字符串格式化时间
public class User {private int id; private Date birthday; private double money; private String name; ...
- 将Java对象序列化成JSON和XML格式
1.先定义一个Java对象Person: public class Person { String name; int age; int number; public String getName() ...
- 使用 EntityFramework后把一个对象序列化成json字符串引起循环引用的问题
先看一个T4模板生成的model实体类 著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:卷猫 链接:http://anneke.cn/ArticleInfo/Detial ...
- 匿名对象序列化为XML
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...
- .net 将List序列化成Json字符串
将List类型转化为Json,是我们平常开发时最常见的了.在使用中,有很多种方法,也可以使用. 第一种 第三方组件:Newtonsoft.Json.dll //转化成Json Newtonsoft.J ...
随机推荐
- Optaplanner终于支持多线程并行运行 - Multithreaded incremental solving
Optaplanner 7.9.0.Final之前,启动引擎开始对一个Problem进行规划的时候,只能是单线程进行的.也就是说,当引擎对每一个possible solution进行分数计算的过程中, ...
- centos7安装rabbitmq3.7.9
感谢此兄: https://blog.51cto.com/huwei555/2341513?source=dra (centos7 安装rabbitmq 3.7) 以root用户登录.cd /hom ...
- DOM 核心
继承在DOM中的重要性: 1. Node 对象 2. Element 对象 3. Document 对象
- Linux常见企业面试题
1:只查看test.txt (100行)文件中第20行到30行的数据(企业常见面试题) 答: seq (序列) 第一种方法:head -30 test1.txt | tail -11 第二种方法:se ...
- chrome的console功能
Console的常用用法: 1:显示信息 常用的有 console.log(),console.info(),console.warn(),console.error() 2:占位符 3:查看对象的信 ...
- Kubernetes及Dashboard详细安装配置(Ubuntu14.04)
前些日子部门计划搞并行开发,需要对开发及测试环境进行隔离,所以打算用kubernetes对docker容器进行版本管理,搭建了下Kubernetes集群,过程如下: 本流程使用了阿里云加速器,配置流程 ...
- Jmeter发送邮件功能SMTP Sampler
介绍Jmeter的发送邮件功能,使用的Sampler是SMTP Sampler,详细说明每个配置项的功能 从上往下介绍需要用到的配置项: Server settings Server: 服务器地址 P ...
- Spring获取URL相关信息
获取请求的URL:request.getRequestURL().toString(); 获取上下文名称(项目名称):request.getContextPath()
- k8s 命令补全
安装:apt-get install bash-completion source <(kubectl completion bash) echo "source <(kubec ...
- (Python基础)最Low三级菜单
#-*-coding:utf-8-*- #_author_: Keep #三级菜单 menu = { '中国':{ '广东省':{ '广州市':{ '海珠区':{}, '荔湾区':{}, '越秀区': ...