当前位置: 首页 > news >正文

网站评估怎么做搜索引擎优化排名关键字广告

网站评估怎么做,搜索引擎优化排名关键字广告,wordpress玻璃透主题,服务器维护内容Json的序列化和反序列化 1.定义数据类 [Serializable] public class ZoomPoint {// 点名称, 将作为Key被字典存储public string name;// 轴心X坐标public Vector2 pivot Vector2.one / 2;// 放大倍率,小于1是为缩小倍率,小于0是取绝对值,不…

Json的序列化和反序列化

1.定义数据类

[Serializable]
public class ZoomPoint
{// 点名称, 将作为Key被字典存储public string name;// 轴心X坐标public Vector2 pivot = Vector2.one / 2;// 放大倍率,小于1是为缩小倍率,小于0是取绝对值,不允许原点对称缩放,需要保证计算轴心逻辑正确// 默认设为1.5f 放大倍率public float zoomMagnification = 5f;// 改变的需要的时间,默认设为1fpublic float time = 1.0f;public override string ToString(){return $"name = {this.name}, pivot = ({pivot.ToString()}), zoomMagnification = {this.zoomMagnification}, time = {this.time}";}
}

2. 定义Json存储类

// 数据存储接受类
[Serializable]
public class Data{// public ZoomPoint[] zoomPoints;// public Dictionary<string, ZoomPoint> zoomPoints;public List<ZoomPoint> zoomPoints;
}

3.序列化

// 写入数据
public void WriteDataTest(){Data data = new(){zoomPoints = new List<ZoomPoint>()};ZoomPoint point1 = new ZoomPoint{name = "1",pivot = new Vector2(0.75f,0.75f)};ZoomPoint point2 = new ZoomPoint{name = "2",pivot = new Vector2(0.5f,0.5f)};data.zoomPoints[0] = point1;data.zoomPoints[1] = point2;string js = JsonUtility.ToJson(data);// 获取项目路径string fileUrl;if(filePath == ""){fileUrl = Application.streamingAssetsPath + jsonFileName;}else{fileUrl = filePath;}using(StreamWriter sw  = new StreamWriter(fileUrl)){   sw.WriteLine(js); //保存数据sw.Close(); sw.Dispose();}
} 

4.反序列化

 public Data ReadData(){// 获取文件路径string fileUrl;if(filePath == ""){fileUrl = Application.streamingAssetsPath + jsonFileName;}else{fileUrl = filePath;}//读取文件string readDate;using (StreamReader sr = File.OpenText(fileUrl)){readDate = sr.ReadLine();sr.Close();}Data data = JsonUtility.FromJson<Data>(readDate);// 分配内存if(data == null ){data = new Data() {zoomPoints = new List<ZoomPoint>()};return data;}// 数据保存到字典里foreach(ZoomPoint zp  in data.zoomPoints){dict.TryAdd(zp.name, zp);}return data;}

数据存储效果:

请添加图片描述


Ps: Unity C# Json 序列化换行

在ToJson中使用两个参数,第二个参数PrettyPrint 输入True
private void JsonText() {Node node = new Node() {name = "Node_01",pos = new(0, 0)};string filePath = Application.streamingAssetsPath + "/Json_01.json";string str = JsonUtility.ToJson(node, true);using (StreamWriter sw = new StreamWriter(filePath)) {sw.WriteLine(str); // 保存数据sw.Close(); // 关闭文档sw.Dispose();}Debug.Log(str);Grid grid = new() {nodes = new List<Node>()};Node node1 = new Node() {name = "Node_01",pos = new Vector2(0, 0)};Node node2 = new Node() {name = "Node_02",pos = new Vector2(0,1)};grid.nodes.Add(node1);grid.nodes.Add(node2);string filePath_01 = Application.streamingAssetsPath + "/Json_02.json";string str_01 = JsonUtility.ToJson(grid, true);using (StreamWriter sw = new StreamWriter(filePath_01)) {sw.WriteLine(str_01); // 保存数据sw.Close(); // 关闭文档sw.Dispose();}Debug.Log("数据序列化完成");
}[Serializable]
public class Node {public string name;public Vector2 pos;
}[Serializable]
public class Grid {public List<Node> nodes;
}

效果:

请添加图片描述

请添加图片描述


Xml的序列化和反序列化

1.定义数据类

public class XmlText {public string name;public string value;public List<int> list;public override string ToString() {return $"name = {name}, value = {value}, list = {list}";}
}

2.序列化

public void Init() {test = new XmlText() {name = "Xml测试",value = "value",list = new List<int>()};test.list.Add(1);test.list.Add(3);test.list.Add(100);}
 // 序列化Xml
public void XmlSerialize() {// 定义流文件FileStream fileStream = new FileStream(Application.streamingAssetsPath + "/text.xml",FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);// 定义写入流StreamWriter sw = new StreamWriter(fileStream, System.Text.Encoding.UTF8);// 位于System.Xml.Serialization 中的Xml序列化XmlSerializer xml = new XmlSerializer(test.GetType());// 将类序列化写入流中xml.Serialize(sw, test);// 关闭流sw.Close();fileStream.Close();
}

3.反序列化

public XmlText Deserialize() {// 流文件FileStream fs = new FileStream(Application.streamingAssetsPath + "/text.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);// 定义序列化类XmlSerializer xml = new XmlSerializer(typeof(XmlText));// 反向序列化XmlText result = (XmlText)xml.Deserialize(fs);fs.Close();return result;}

结果:

请添加图片描述

http://www.zhongyajixie.com/news/55563.html

相关文章:

  • 深圳网站备案注销第一设计
  • 你做网站群好朋友的作文网站如何推广
  • 程序员做项目的网站软文案例大全300字
  • 网站建设算什么资产百度移动点击排名软件
  • 手机价格网站建设站长素材官网免费
  • 青岛做网站建设站长之家音效素材
  • WordPress仿牌seo运营学校
  • 网站制作复杂吗网络营销平台推广方案
  • 济南建设委员会网站手机如何创建网站
  • 专门提供做ppt小素材的网站seo外链发布平台
  • 建站公司的服务器镇江seo优化
  • 广州技术支持 网站建设娄底seo
  • 自己做导航网站衡阳网站建设公司
  • 做网站要找什么公司qq推广
  • 旅游网站的市场需求怎么做介绍优化培训课程
  • 荆州网站建设流程企业建站平台
  • 深圳的公司排名唐山seo优化
  • 大片网址搜索引擎seo排名优化
  • 下载app赚钱的平台南京seo圈子
  • 滨州聊城网站建设珠海企业网站建设
  • 网站建设中 英语免费创建网站软件
  • 网站建设优化项目在线seo诊断
  • php做网站开源项目web网页制作成品免费
  • 网站建设企业开源百度旗下产品
  • 怎么免费建立一个网站关键词首页优化
  • 企业建设H5响应式网站的5大好处线上营销的方式
  • 网站推广方案案例手机营销推广方案
  • 做珠宝建个网站推广怎么样品牌如何推广
  • 优秀的门户网站seo引擎优化公司
  • 高端网站建设 南京搜索引擎关键词seo优化公司