XML跳过utf-8的BOM
来源:互联网 发布:cda数据分析师报名费用 编辑:程序博客网 时间:2024/06/06 00:53
代码内容
GameData GetDataWithoutBOM(string fileName) { GameData data = new GameData(); Stream stream = new FileStream(fileName + @"\data.json", FileMode.Open, FileAccess.Read, FileShare.None); StreamReader streamReader = new StreamReader(stream, true);//true跳过bom XmlSerializer xmlSerializer = new XmlSerializer(data.GetType()); data = xmlSerializer.Deserialize(streamReader) as GameData; streamReader.Close(); stream.Close(); return data; }
fliename就是我们存放的文件路径,文件是json格式的,这里通过流式读取来跳过bom,并且通过序列化获取数据,关于GameData这个类是我的自定义的数据存储类型。
/// <summary>/// 存储数据类型/// </summary>[System.Serializable]public class GameData{ public int playerIntegration; public int computerOneIntegration; public int computerTwoIntegration;}
我的data.json文件中的内容如下:
<?xml version="1.0" encoding="utf-8"?><GameData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <playerIntegration>700</playerIntegration> <computerOneIntegration>1200</computerOneIntegration> <computerTwoIntegration>700</computerTwoIntegration></GameData>
以上方法是用代码来去除bom,其实用notepad++来重新编辑保存是更简单的,亲测可行。
0 0
- XML跳过utf-8的BOM
- utf-8 bom 对 xml 的影响
- UTF-8的BOM问题
- UTF-8的BOM问题
- UTF-8的BOM头
- UTF-8的BOM问题
- 关于UTF-8的BOM
- UTF-8的BOM头
- UTF-8的bom问题
- UTF-8 NO BOM & BOM
- BOM utf-8 的去掉BOM的方法
- UTF-8 的BOM带来的麻烦
- UTF-8 的BOM带来的麻烦
- UTF-8 的BOM带来的麻烦
- php utf-8的 BOM 问题解决
- 关于UTF-8文件的BOM签名
- PHP UTF-8的 BOM 问题解决
- 我靠~UTF-8的BOM
- to_char()----用法
- DAY10_USE OF TOOL
- AWS搭建VPN记录
- 使用ApacheBench对nginx进行压测实验
- HDU 1272 小希的迷宫(并查集)
- XML跳过utf-8的BOM
- jQuery控制input的value值,代码中有值,但是页面中不能显示的原因
- SQL注入-入门篇
- 同部电脑运行多个tomcat
- JAVA通过JDBC连接数据库
- MyEclipse2014修改web项目部署的名称
- vtk
- Your app declares support for location in the UIBackgroundModes key in your Info.plist file but does
- python连接mysql