IOSerialize,xml和json,soap序列化器,二進位序列化器,XML序列化器,文件 檢查、新增、複製、移動、刪除

来源:http://www.cnblogs.com/AnkerZhang/archive/2017/07/12/7156466.html
-Advertisement-
Play Games

1 文件夾/文件 檢查、新增、複製、移動、刪除,2 文件讀寫,記錄文本日誌/讀取配置文件3 三種序列化器4 xml和json1.文件夾/文件 檢查、新增、複製、移動、刪除,2 文件讀寫,記錄文本日誌/讀取配置文件 日誌方法 3 三種序列化器 在序列化類之前先用 [Serializable] //必須 ...


1 文件夾/文件 檢查、新增、複製、移動、刪除,
2 文件讀寫,記錄文本日誌/讀取配置文件
3 三種序列化器
4 xml和json
1.文件夾/文件 檢查、新增、複製、移動、刪除,2 文件讀寫,記錄文本日誌/讀取配置文件

using System.IO;
/// <summary> /// 配置絕對路徑 /// </summary> private static string LogPath = ConfigurationManager.AppSettings["LogPath"]; private static string LogMovePath = ConfigurationManager.AppSettings["LogMovePath"]; /// <summary> /// 獲取當前程式路徑 /// </summary> private static string LogPath2 = AppDomain.CurrentDomain.BaseDirectory;
         DirectoryInfo directory = new DirectoryInfo(LogPath);//不存在不報錯  註意exists屬性
                directory.FullName;//獲取目錄或文件的完整目錄。
                directory.CreationTime;//獲取或設置當前文件或目錄的創建時間。
                directory.LastWriteTime;//獲取或設置上次寫入當前文件或目錄的時間。
                Path.Combine(LogPath, "info.txt");// 將兩個字元串組合成一個路徑。
                FileInfo fileInfo = new FileInfo(Path.Combine(LogPath, "info.txt"));//提供創建、複製、刪除、移動和打開文件的屬性和實例方法,並且幫助創建 System.IO.FileStream 對象。 此類不能被繼承。
                Directory.Exists(LogPath);//檢測文件夾是否存在
{//File
                string fileName = Path.Combine(LogPath, "log.txt");
                string fileNameCopy = Path.Combine(LogPath, "logCopy.txt");
                string fileNameMove = Path.Combine(LogPath, "logMove.txt");
                bool isExists = File.Exists(fileName);
                if (!isExists)
                {
                    Directory.CreateDirectory(LogPath);
                    using (FileStream fileStream = File.Create(fileName))//打開文件流 (創建文件並寫入)
                    {
                        string name = "12345567778890";
                        byte[] bytes = Encoding.Default.GetBytes(name);
                        fileStream.Write(bytes, 0, bytes.Length);
                        fileStream.Flush();
                    }
                    using (FileStream fileStream = File.Create(fileName))//打開文件流 (創建文件並寫入)
                    {
                        StreamWriter sw = new StreamWriter(fileStream);
                        sw.WriteLine("1234567890");
                        sw.Flush();
                    }

                    using (StreamWriter sw = File.AppendText(fileName))//流寫入器(創建/打開文件並寫入)
                    {
                        string msg = "今天是Course6IOSerialize,今天上課的人有55個人";
                        sw.WriteLine(msg);
                        sw.Flush();
                    }
                    using (StreamWriter sw = File.AppendText(fileName))//流寫入器(創建/打開文件並寫入)
                    {
                        string name = "0987654321";
                        byte[] bytes = Encoding.Default.GetBytes(name);
                        sw.BaseStream.Write(bytes, 0, bytes.Length);
                        sw.Flush();
                    }



                    foreach (string result in File.ReadAllLines(fileName))
                    {
                        Console.WriteLine(result);
                    }
                    string sResult = File.ReadAllText(fileName);
                    Byte[] byteContent = File.ReadAllBytes(fileName);
                    string sResultByte = System.Text.Encoding.UTF8.GetString(byteContent);

                    using (FileStream stream = File.OpenRead(fileName))//分批讀取
                    {
                        int length = 5;
                        int result = 0;

                        do
                        {
                            byte[] bytes = new byte[length];
                            result = stream.Read(bytes, 0, 5);
                            for (int i = 0; i < result; i++)
                            {
                                Console.WriteLine(bytes[i].ToString());
                            }
                        }
                        while (length == result);
                    }

                    File.Copy(fileName, fileNameCopy);
                    File.Move(fileName, fileNameMove);
                    File.Delete(fileNameCopy);
                    File.Delete(fileNameMove);//儘量不要delete
                }
            }
{//DriveInfo
                DriveInfo[] drives = DriveInfo.GetDrives();

                foreach (DriveInfo drive in drives)
                {
                    if (drive.IsReady)
                        Console.WriteLine("類型:{0} 捲標:{1} 名稱:{2} 總空間:{3} 剩餘空間:{4}", drive.DriveType, drive.VolumeLabel, drive.Name, drive.TotalSize, drive.TotalFreeSpace);
                    else
                        Console.WriteLine("類型:{0}  is not ready", drive.DriveType);
                }

            }
{
                Console.WriteLine(Path.GetDirectoryName(LogPath));  //返回目錄名,需要註意路徑末尾是否有反斜杠對結果是有影響的
                Console.WriteLine(Path.GetDirectoryName(@"d:\\abc")); //將返回 d:\
                Console.WriteLine(Path.GetDirectoryName(@"d:\\abc\"));// 將返回 d:\abc
                Console.WriteLine(Path.GetRandomFileName());//將返回隨機的文件名
                Console.WriteLine(Path.GetFileNameWithoutExtension("d:\\abc.txt"));// 將返回abc
                Console.WriteLine(Path.GetInvalidPathChars());// 將返回禁止在路徑中使用的字元
                Console.WriteLine(Path.GetInvalidFileNameChars());//將返回禁止在文件名中使用的字元
                Console.WriteLine(Path.Combine(LogPath, "log.txt"));//合併兩個路徑
            }

日誌方法

 /// <summary>
        ////// 1  try catch旨在上端使用,保證對用戶的展示
        /// 2  下端不要吞掉異常,隱藏錯誤是沒有意義的,抓住再throw也沒意義
        /// 3  除非這個異常對流程沒有影響或者你要單獨處理這個異常
        /// </summary>
        /// <param name="msg"></param>
        public static void Log(string msg)
        {
            StreamWriter sw = null;
            try
            {
                string fileName = "log.txt";
                string totalPath = Path.Combine(LogPath, fileName);

                if (!Directory.Exists(LogPath))
                {
                    Directory.CreateDirectory(LogPath);
                }
                sw = File.AppendText(totalPath);
                sw.WriteLine(string.Format("{0}:{1}", DateTime.Now, msg));
                sw.WriteLine("***************************************************");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);//log
                //throw ex;
                //throw new exception("這裡異常");
            }
            finally
            {
                if (sw != null)
                {
                    sw.Flush();
                    sw.Close();
                    sw.Dispose();
                }
            }
        }

3 三種序列化器

在序列化類之前先用 [Serializable]  //必須添加序列化特性

不序列化的屬性使用[NonSerialized] 特性標記

/// <summary>
        /// 二進位序列化器
        /// </summary>
        public static List<Programmer> BinarySerialize(List<Programmer> list)
        {
            //使用二進位序列化對象
            string fileName = Path.Combine("路徑地址", @"BinarySerialize.txt");//文件名稱與路徑
            using (Stream fStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite))
            {//需要一個stream,這裡是直接寫入文件了
                BinaryFormatter binFormat = new BinaryFormatter();//創建二進位序列化器
                binFormat.Serialize(fStream, list);
            }
            //反序列化
            using (Stream fStream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
            {//需要一個stream,這裡是來源於文件
                BinaryFormatter binFormat = new BinaryFormatter();//創建二進位序列化器
                //使用二進位反序列化對象
                fStream.Position = 0;//重置流位置
                List<Programmer> pList = (List<Programmer>)binFormat.Deserialize(fStream);//反序列化對象
                return pList;
            }
        }
 /// <summary>
        /// soap序列化器
        /// </summary>
        public static List<Programmer> SoapSerialize(List<Programmer> list)
        {
            //使用Soap序列化對象
            string fileName = Path.Combine("路徑地址", @"SoapSerialize.txt");//文件名稱與路徑
            using (Stream fStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite))
            {
                SoapFormatter soapFormat = new SoapFormatter();//創建二進位序列化器
                //soapFormat.Serialize(fStream, list);//SOAP不能序列化泛型對象
                soapFormat.Serialize(fStream, list.ToArray());
            }
            using (Stream fStream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
            {
                SoapFormatter soapFormat = new SoapFormatter();//創建二進位序列化器
                //使用二進位反序列化對象
                fStream.Position = 0;//重置流位置
                List<Programmer> pList = ((Programmer[])soapFormat.Deserialize(fStream)).ToList();//反序列化對象
                return pList;
            }
        }
/// <summary>
        /// XML序列化器
        /// </summary>
        public static List<Programmer> XmlSerialize(List<Programmer> List)
        {
            //使用XML序列化對象
            string fileName = Path.Combine("路徑", @"Student.xml");//文件名稱與路徑
            using (Stream fStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite))
            {
                XmlSerializer xmlFormat = new XmlSerializer(typeof(List<Programmer>));//創建XML序列化器,需要指定對象的類型
                xmlFormat.Serialize(fStream, List);
            }
            using (Stream fStream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
            {
                XmlSerializer xmlFormat = new XmlSerializer(typeof(List<Programmer>));//創建XML序列化器,需要指定對象的類型
                //使用XML反序列化對象
                fStream.Position = 0;//重置流位置
                List<Programmer> pList = pList = (List<Programmer>)xmlFormat.Deserialize(fStream);
                return pList;
            }
        }
//BinaryFormatter序列化自定義類的對象時,序列化之後的流中帶有空字元,以致於無法反序列化,反序列化時總是報錯“在分析完成之前就遇到流結尾”(已經調用了stream.Seek(0, SeekOrigin.Begin);)。
//改用XmlFormatter序列化之後,可見流中沒有空字元,從而解決上述問題,但是要求類必須有無參數構造函數,而且各屬性必須既能讀又能寫,即必須同時定義getter和setter,若只定義getter,則反序列化後的得到的各個屬性的值都為null。
using Newtonsoft.Json;


public class JsonHelper
    {
        #region Json
        /// <summary>
        /// JavaScriptSerializer
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string ObjectToString<T>(T obj)
        {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            return jss.Serialize(obj);
        }

        /// <summary>
        /// JavaScriptSerializer
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="content"></param>
        /// <returns></returns>
        public static T StringToObject<T>(string content)
        {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            return jss.Deserialize<T>(content);
        }

        /// <summary>
        /// JsonConvert.SerializeObject
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string ToJson<T>(T obj)
        {
            return JsonConvert.SerializeObject(obj);
        }

        /// <summary>
        /// JsonConvert.DeserializeObject
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="content"></param>
        /// <returns></returns>
        public static T ToObject<T>(string content)
        {
            return JsonConvert.DeserializeObject<T>(content);
        }

        #endregion Json
    }

 

using System.IO;
/// <summary>
        /// 找出全部的子文件夾
        /// </summary>
        /// <param name="rootPath">根目錄</param>
        /// <returns></returns>
        public static List<DirectoryInfo> GetAllDirectory(string rootPath)
        {
            List<DirectoryInfo> directoryList = new List<DirectoryInfo>();

            DirectoryInfo directory = new DirectoryInfo(rootPath);
            
            GetChildDirectory(directoryList, directory);

            return directoryList;
        }


        /// <summary>
        /// 找出某個文件夾的子文件夾,,放入集合
        /// 
        /// 遞歸:方法自身調用自身
        /// </summary>
        /// <param name="directoryList"></param>
        /// <param name="parentDirectory"></param>
        private static void GetChildDirectory(List<DirectoryInfo> directoryList, DirectoryInfo parentDirectory)
        {
            directoryList.AddRange(parentDirectory.GetDirectories());
            if (parentDirectory.GetDirectories() != null && parentDirectory.GetDirectories().Length > 0)
            {
                foreach (var directory in parentDirectory.GetDirectories())
                {
                    GetChildDirectory(directoryList, directory);
                }
            }
        }

XML 與實體字元串轉換

 public static class xHelper
    {
        /// <summary>   
        /// 實體轉化為XML   
        /// </summary>   
        public static string ParseToXml<T>(this T model, string fatherNodeName)
        {
            var xmldoc = new XmlDocument();
            var modelNode = xmldoc.CreateElement(fatherNodeName);
            xmldoc.AppendChild(modelNode);

            if (model != null)
            {
                foreach (PropertyInfo property in model.GetType().GetProperties())
                {
                    var attribute = xmldoc.CreateElement(property.Name);
                    if (property.GetValue(model, null) != null)
                        attribute.InnerText = property.GetValue(model, null).ToString();
                    //else
                    //    attribute.InnerText = "[Null]";
                    modelNode.AppendChild(attribute);
                }
            }
            return xmldoc.OuterXml;
        }

        /// <summary>   
        /// XML轉換為實體,預設 fatherNodeName="body"
        /// </summary> 
        public static T ParseToModel<T>(this string xml, string fatherNodeName = "body") where T : class ,new()
        {
            T model = new T();
            if (string.IsNullOrEmpty(xml))
                return default(T);
            var xmldoc = new XmlDocument();
            xmldoc.LoadXml(xml);

            var attributes = xmldoc.SelectSingleNode(fatherNodeName).ChildNodes;
            foreach (XmlNode node in attributes)
            {
                foreach (var property in model.GetType().GetProperties().Where(property => node.Name == property.Name))
                {
                    if (!string.IsNullOrEmpty(node.InnerText))
                    {
                        property.SetValue(model,
                                          property.PropertyType == typeof(Guid)
                                              ? new Guid(node.InnerText)
                                              : Convert.ChangeType(node.InnerText, property.PropertyType), null);
                    }
                    else
                        property.SetValue(model, null, null);
                }
            }
            return model;
        }

        /// <summary>
        /// XML轉實體
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="xml"></param>
        /// <param name="headtag"></param>
        /// <returns></returns>
        public static List<T> XmlToObjList<T>(this string xml, string headtag)
            where T : new()
        {

            var list = new List<T>();
            XmlDocument doc = new XmlDocument();
            PropertyInfo[] propinfos = null;
            doc.LoadXml(xml);
            //XmlNodeList nodelist = doc.SelectNodes(headtag);  
            XmlNodeList nodelist = doc.SelectNodes(headtag);
            foreach (XmlNode node in nodelist)
            {
                T entity = new T();
                //初始化propertyinfo  
                if (propinfos == null)
                {
                    Type objtype = entity.GetType();
                    propinfos = objtype.GetProperties();
                }
                //填充entity類的屬性  
                foreach (PropertyInfo propinfo in propinfos)
                {
                    //實體類欄位首字母變成小寫的  
                    string name = propinfo.Name.Substring(0, 1) + propinfo.Name.Substring(1, propinfo.Name.Length - 1);
                    XmlNode cnode = node.SelectSingleNode(name);
                    string v = cnode.InnerText;
                    if (v != null)
                        propinfo.SetValue(entity, Convert.ChangeType(v, propinfo.PropertyType), null);
                }
                list.Add(entity);

            }
            return list;

        }
    }

 

public class XmlHelper
    {
        private static string CurrentXMLPath = ConfigurationManager.AppSettings["CurrentXMLPath"];
        /// <summary>
        /// 通過XmlSerializer序列化實體
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        public static string ToXml<T>(T t) where T : new()
        {
            XmlSerializer xmlSerializer = new XmlSerializer(t.GetType());
            Stream stream = new MemoryStream();
            xmlSerializer.Serialize(stream, t);
            stream.Position = 0;  
            StreamReader reader = new StreamReader( stream );  
            string text = reader.ReadToEnd();  
            return text;

            //string fileName = Path.Combine(CurrentXMLPath, @"Person.xml");//文件名稱與路徑
            //using (Stream fStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite))
            //{
            //    XmlSerializer xmlFormat = new XmlSerializer(typeof(T));
            //    xmlFormat.Serialize(fStream, t);
            //}
            //string[] lines = File.ReadAllLines(fileName);
            //return string.Join("", lines);
        }

        /// <summary>
        /// 字元串序列化成XML
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="content"></param>
        /// <returns></returns>
        public static T ToObject<T>(string content) where T : new()
        {
            using (MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(content)))
            {
                XmlSerializer xmlFormat = new XmlSerializer(typeof(T));
                return (T)xmlFormat.Deserialize(stream);
            }

            //string fileName = Path.Combine(CurrentXMLPath, @"Person.xml");
            //using (Stream fStream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
            //{
            //    XmlSerializer xmlFormat = new XmlSerializer(typeof(T));
            //    return (T)xmlFormat.Deserialize(fStream);
            //}
        }

        /// <summary>
        /// 文件反序列化成實體
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static T FileToObject<T>(string fileName) where T : new()
        {
            fileName = Path.Combine(CurrentXMLPath, @"Student.xml");
            using (Stream fStream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
            {
                XmlSerializer xmlFormat = new XmlSerializer(typeof(T));
                return (T)xmlFormat.Deserialize(fStream);
            }
        }

        /*   linq to xml
                public static IEnumerable<Hero<T>> GetHeroEntity(string fileName)
                {
                    XDocument xdoc = XDocument.Load(fileName);
                    XElement root = xdoc.Root;
                    foreach (XElement element in root.Elements())
                    {
                        Hero<T> entity = new Hero<T>();
                        entity.Name = element.Element("Name").Value;
                        foreach (XElement item in element.Element("StoryCollection").Elements())
                        {
                            var story = ReflectionUtils<T>.ElementToEntity(item);
                            entity.list.Add(story);
                        }
                        yield return entity;
                    }
                }

                /// <summary>
                /// 將XElement轉換為T類型的實體類
                /// </summary>
                /// <param name="xe">XElement</param>
                /// <returns>T類型的實體類</returns>
                public static T ElementToEntity<T>(XElement xe)
                {
                    T entity = Activator.CreateInstance<T>(); //T entity = new T();
                    Type type = typeof(T);
                    PropertyInfo[] properties = type.GetProperties();
                    foreach (PropertyInfo p in properties)
                    {
                        string propertyName = p.Name;
                        Type propertyType = p.PropertyType;
                        object obj = xe.Element(propertyName).Value;
                        object value = Convert.ChangeType(obj, propertyType);
                        p.SetValue(entity, value);
                    }
                    return entity;
                }
                */
    }

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • LINUX是開源的,這也是最主要的原因,想學Windows,Unix對不起,沒有源代碼。也正是因為這樣,LINUX才能夠像雪球一樣越滾越大,發展到現在這種規模。今天將為大家帶來關於Linux主流框架運維工作剖析,大家一定要認真閱讀哦~ 隨著IT運維的不斷發展,尤其的Linux的飛速發展,越來越多的企 ...
  • Win7 U盤安裝Ubuntu16.04 雙系統詳細教程 安裝主要分為以下幾步: 一. 下載Ubuntu 16.04鏡像軟體; 二. 製作U盤啟動盤使用ultraISO; 三. 安裝Ubuntu系統; 四. 用EasyBCD 創建啟動系統啟動引導; (根據個人情況,選擇性的安裝) 五. 開啟系統; ...
  • 5. 獲取進程名、進程號以及用戶 ID 查看埠和連接的信息時,能查看到它們對應的進程名和進程號對系統管理員來說是非常有幫助的。舉個慄子,Apache 的 httpd 服務開啟80埠,如果你要查看 http 服務是否已經啟動,或者 http 服務是由 apache 還是 nginx 啟動的,這時候 ...
  • 介紹什麼的就免了.直接進入正題 平臺: Windows 10 IDE : Visual studio 2017 首先從官網下載最新的SDK,https://sciter.com/download/ 創建流程. https://sciter.com/forums/topic/simple-questi ...
  • 解決網卡無法自動獲取IP址的方法 為了省錢或者一戶多機,很多人都購買寬頻路由器共用上網。在架設路由上網的時候,有些“師傅”可能不懂或是偷懶,開啟了寬頻路由器的DHCP( Dynamic Host Configuration Protocol(動態主機分配協議))功能,這樣,其他機子只要設置“自動獲取 ...
  • 背水一戰 Windows 10 之 控制項(集合類 - ListViewBase): ListView, GridView ...
  • 因為這個解法有點複雜,因此單獨開一貼介紹。《演算法(第四版)》中的題目是這樣的:1.3.49棧與隊列。用有限個棧實現一個隊列,保證每個隊列操作(在最壞情況下)都只需要常數次的棧操作。那麼這裡就使用六個棧來解決這個問題。這個演算法來自於這篇論文。原文里用的是 Pure Lisp,不過語法很簡單,還是很容易... ...
  • 一、摘要 1.1、為什麼叫本次的分享課叫《修煉手冊》? 阿笨希望本次的分享課中涉及覆蓋的一些小技巧、小技能給您帶來一些幫助。希望您在日後工作中把它作為一本實際技能手冊進行儲備,以備不時之需,一旦當手頭遇到與Dapper修煉手冊中相似用法的地方和場景,可以直接拿來進行翻閱並靈活的運用到項目中。最後阿笨 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...