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; }
        }
    }

  • 相关阅读:
    leetcode-15 三数之和
    leetcode-113 路径之和
    leetcode-112 路径之和
    leetcode-1 两数之和
    leetcode-215 第k大元素
    leetcode 698 集合k划分
    编程之法之字符串
    LeetCode 830. Positions of Large Groups
    LeetCode 821. Shortest Distance to a Character
    LeetCode 213. House Robber II
  • 原文地址:https://www.cnblogs.com/rockniu/p/1510339.html
Copyright © 2011-2022 走看看