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

  • 相关阅读:
    Pandas中dataframe以及spark中rdd使用groupByKey进行合并
    Apriori算法Python实现
    安装Cloudera CDH
    HDFS常用命令
    vuex modules 命名空间
    sessionStore使用
    indexof使用
    vue 简单购物车实现
    etCapture() 和 ReleaseCapture()的用法
    js组合继承与寄生继承
  • 原文地址:https://www.cnblogs.com/rockniu/p/1510339.html
Copyright © 2011-2022 走看看