X3

RedSky

导航

C#解决XML反序列化空格值被忽略的问题

解决办法:将XmlReaderSettings的值CheckCharacters = false

如下:

                using (StreamReader sr = new StreamReader(xmlfilePath))
                {
                    var setting = new XmlReaderSettings
                    {
                        CheckCharacters = false
                    };
                    using (XmlReader r = XmlReader.Create(sr, setting))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(T));
                        return (T)serializer.Deserialize(r);
                    }
                }

 

posted on 2022-06-22 18:00  HotSky  阅读(374)  评论(0编辑  收藏  举报