zoukankan      html  css  js  c++  java
  • 序列化Xml时指定字符集的方法

    Sample:

    untitled

    代码:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;

    namespace ChangedIndicator
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                System.Xml.Serialization.XmlSerializer xs
                    = new System.Xml.Serialization.XmlSerializer(typeof(MyCls));

                MyCls obj = new MyCls { Id = 1, Name = "Rock Niu" };

                using (MemoryStream mStream = new MemoryStream())
                {
                    TextWriter tw = new StreamWriter(mStream, Encoding.UTF8);
                    xs.Serialize(tw, obj);

                    richTextBox1.Text = Encoding.UTF8.GetString(mStream.ToArray());
                }
            }
        }

        public class MyCls
        {
            public int Id { get; set; }
            public string Name { get; set; }
        }
    }

  • 相关阅读:
    eclipse 插件编写(三)(转)
    eclipse 插件编写(二)
    eclipse 插件编写(一)(转)
    js 中的 this 关键字
    js中创建对象的几种方式
    js 如何中如何理解对象?
    项目中的小技巧
    王国维的诗
    uni-app 基础组件
    登庐山 毛
  • 原文地址:https://www.cnblogs.com/rockniu/p/1510339.html
Copyright © 2011-2022 走看看