Newtonsoft.Json C# Json序列化和反序列化工具的使用、類型方法大全

来源:https://www.cnblogs.com/whuanle/archive/2019/02/06/10353759.html
-Advertisement-
Play Games

Newtonsoft.Json Newtonsoft.Json 是.Net平臺操作Json的工具,他的介紹就不多說了,筆者最近在弄介面,需要操作Json。 以某個雲計算平臺的Token為例,邊操作邊講解。 Json 轉為 Model 將 Model 轉為 Json 將 LINQ 轉為 JSON Li ...


 Newtonsoft.Json

Newtonsoft.Json 是.Net平臺操作Json的工具,他的介紹就不多說了,筆者最近在弄介面,需要操作Json。

以某個雲計算平臺的Token為例,邊操作邊講解。

Json 轉為 Model

將 Model 轉為 Json

將 LINQ 轉為 JSON

Linq 操作

命名空間、類型、方法大全

另外附上 百度AI 文字識別 Json 及其模型類

 

 Newtonsoft.Json 將字元串轉為對象,是根據類型對象名稱進行的,大小寫不分,但是名稱要一致要,哪怕你的json只有一個

{

"a":1

}

你的對象

public class Test

    {
        public int aa{get;set;}
    }

也是不能對應的。

有複雜層次的 json,可以使用 “類中類” 來映射,要註意 List<T>/Array/ArrayList的類型的使用。


 Json 轉為 Model

 

新建一個 Json 文件,名字隨意,例如 json1.json

把以下內容粘貼進去

{
  "refresh_token": "25.ea2f85ebd48df85fe5400000.18640.282335-15533349",
  "expires_in": 2592010,
  "session_key": "9mzdWr3n8ncMeDgX8zjhkhlW8khb5cdZtPevPbPwQGBg==",
  "access_token": "24.ac0ca9fakhlkyhl552017858.282335-15533349",
  "scope": "audio_voice_assistant_get audio_tts_post public vis-ocr_ocr nlp_simnet nlp_wclassify_watermark brain_ocr_scope vis-classify_car brain_gif_antiporn brain_ocr_general brain_ocr_general_basic brain_ocr_generer vis-classify_animal brain_politician brain_unit_utterance brain_imgquality_general brain_nlp_simnet brain_nlp_depparser vis-classify_plant brain_solution brain_ocr_plate_number brain_nlp_wordembedding brain_nlp_dnnlm_cn_legacy brain_nlp_simnet_legacy brain_nlp_commain_animal_classify brain_plant_classify brain_solution_iocr brain_realtime_product brain_nlp_lexer_custom brain_kgbody_analysis brain_body_attr brain_ocr_vat_invoice brain_advanced_general_classify brain_numbers brain_body_number vis-faceverify_FACE_auth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi",
  "session_secret": "2ca66d464545c77a4767f709873be4"
}

 

定義一個模型,文件名為 AccessTokenModel.cs

    public class AccessTokenModel
    {
        public string refresh_token { get; set; }
        public string expires_in { get; set; }//: Access Token的有效期(秒為單位,一般為1個月)
        public string scope { get; set; }
        public string session_key { get; set; }
        public string access_token { get; set; }//: 要獲取的Access Token
        public string session_secret { get; set; }
    }

打開 Program.cs 文件

            public static void Main(string[] args)
            {
                FileStream fs = new FileStream(@"請修改成你的文件路徑\json1.json", FileMode.Open);
                StreamReader fileStream = new StreamReader(fs);
                string str = "";
                string line;
                while ((line = fileStream.ReadLine()) != null)
                {
                    str += line;
                }
          //上面的代碼沒有意義,只是將Json文件的內容載入到字元串中
           JObject jObject
= new JObject();        //新建 操作對象 AccessTokenModel a = JsonConvert.DeserializeObject<AccessTokenModel>(str); Console.WriteLine(a.access_token);    //隨意輸出一個屬性 Console.ReadKey(); }

 重點方法 

JsonConvert.DeserializeObject<要轉化的模型類>("字元串對象");

之後可以很方便的把Json文件的內容存放到資料庫中。

集合

把Json文件改成以下的樣子

[{
  "refresh_token": "25.ea2f85ebd48df85fe5400000.18640.282335-15533349",
  "expires_in": 2592010,
  "session_key": "9mzdWr3n8ncMeDgX8zjhkhlW8khb5cdZtPevPbPwQGBg==",
  "access_token": "24.ac0ca9fakhlkyhl552017858.282335-15533349",
  "scope": "audio_voice_assistant_get audio_tts_post public vis-ocr_ocr nlp_simnet nlp_wclassify_watermark brain_ocr_scope vis-classify_car brain_gif_antiporn brain_ocr_general brain_ocr_general_basic brain_ocr_generer vis-classify_animal brain_politician brain_unit_utterance brain_imgquality_general brain_nlp_simnet brain_nlp_depparser vis-classify_plant brain_solution brain_ocr_plate_number brain_nlp_wordembedding brain_nlp_dnnlm_cn_legacy brain_nlp_simnet_legacy brain_nlp_commain_animal_classify brain_plant_classify brain_solution_iocr brain_realtime_product brain_nlp_lexer_custom brain_kgbody_analysis brain_body_attr brain_ocr_vat_invoice brain_advanced_general_classify brain_numbers brain_body_number vis-faceverify_FACE_auth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi",
  "session_secret": "2ca66d464545c77a4767f709873be4"
},
{
  "refresh_token": "25.ea2f85ebd48df85fe5400000.18640.282335-15533349",
  "expires_in": 2592010,
  "session_key": "9mzdWr3n8ncMeDgX8zjhkhlW8khb5cdZtPevPbPwQGBg==",
  "access_token": "24.ac0ca9fakhlkyhl552017858.282335-15533349",
  "scope": "audio_voice_assistant_get audio_tts_post public vis-ocr_ocr nlp_simnet nlp_wclassify_watermark brain_ocr_scope vis-classify_car brain_gif_antiporn brain_ocr_general brain_ocr_general_basic brain_ocr_generer vis-classify_animal brain_politician brain_unit_utterance brain_imgquality_general brain_nlp_simnet brain_nlp_depparser vis-classify_plant brain_solution brain_ocr_plate_number brain_nlp_wordembedding brain_nlp_dnnlm_cn_legacy brain_nlp_simnet_legacy brain_nlp_commain_animal_classify brain_plant_classify brain_solution_iocr brain_realtime_product brain_nlp_lexer_custom brain_kgbody_analysis brain_body_attr brain_ocr_vat_invoice brain_advanced_general_classify brain_numbers brain_body_number vis-faceverify_FACE_auth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi",
  "session_secret": "2ca66d464545c77a4767f709873be4"
}
]

 

            public static void Main(string[] args)
            {
                FileStream fs = new FileStream(@"請修改成你的文件路徑\json1.json", FileMode.Open);
                StreamReader fileStream = new StreamReader(fs);
                string str = "";
                string line;
                while ((line = fileStream.ReadLine()) != null)
                {
                    str += line;
                }
                //上面的代碼沒有意義,只是將Json文件的內容載入到字元串中

                JObject jObject = new JObject();        //新建 操作對象
                List<AccessTokenModel> a = JsonConvert.DeserializeObject<List<AccessTokenModel>>(str);
                foreach (var i in a)
                {
                    Console.WriteLine(i.access_token);
                }

                Console.ReadKey();
            }

 


將Model轉為Json

能夠將模型對象轉為 Json。

繼續使用上面的 AccessTokenModel.cs 文件,

            public static void Main(string[] args)
            {
                AccessTokenModel accessTokenModel = new AccessTokenModel();
                accessTokenModel.access_token = "test1";
                accessTokenModel.expires_in = "test2";
                accessTokenModel.refresh_token = "test3";
                accessTokenModel.scope = "test4";
                accessTokenModel.session_key = "test5";
                accessTokenModel.session_secret = "test6";

                JObject jObject = new JObject();
                string str = JsonConvert.SerializeObject(accessTokenModel);    //轉為字元串

                Console.WriteLine(str);
                Console.ReadKey();
            }

重點方法 

JsonConvert.SerializeObject(a模型對象);

運行後可以看到控制台輸出的是Json字元串了,你可以繼續把他放到Json文件中,這裡不再贅述。


將 LINQ 轉為 JSON

下麵這個是從官網直接copy的例子,Jarray 是其框架提供的一種類型。

在控制台運行後會發現輸出的字元是已經格式化的。

            public static void Main(string[] args)
            {
                JArray array = new JArray();
                array.Add("Manual text");
                array.Add(new DateTime(2000, 5, 23));

                JObject o = new JObject();
                o["MyArray"] = array;

                string json = o.ToString();
                // {
                //   "MyArray": [
                //     "Manual text",
                //     "2000-05-23T00:00:00"
                //   ]
                // }

                Console.WriteLine(json);
                Console.ReadKey();

 


Linq 操作

框架提供了對 Jobject 對象的Linq操作支持

using Newtonsoft.Json.Linq;

之後你可以像操作數組、集合或者Context一樣方便。

 


命名空間、類型、方法大全

本來想翻譯一下的,英語太差,算了。在常用的類型前面加粗吧

 

Classes
 ClassDescription
Public class DefaultJsonNameTable The default JSON name table implementation.
Public class JsonArrayAttribute Instructs the JsonSerializer how to serialize the collection.
Public class JsonConstructorAttribute Instructs the JsonSerializer to use the specified constructor when deserializing that object.
Public class JsonContainerAttribute Instructs the JsonSerializer how to serialize the object.
Public classCode example JsonConvert 提供用於在.NET 和 Json之間互相轉等操作的方法
Public class JsonConverter Converts an object to and from JSON.
Public class JsonConverter<T> Converts an object to and from JSON.
Public class JsonConverterAttribute Instructs the JsonSerializer to use the specified JsonConverter when serializing the member or class.
Public class JsonConverterCollection Represents a collection of JsonConverter.
Public class JsonDictionaryAttribute Instructs the JsonSerializer how to serialize the collection.
Public class JsonException JSON序列化或反序列化過程中發生錯誤時引發的異常類型
Public class JsonExtensionDataAttribute Instructs the JsonSerializer to deserialize properties with no matching class member into the specified collection and write values during serialization.
Public class JsonIgnoreAttribute Instructs the JsonSerializer not to serialize the public field or public read/write property value.
Public class JsonNameTable Base class for a table of atomized string objects.
Public class JsonObjectAttribute Instructs the JsonSerializer how to serialize the object.
Public class JsonPropertyAttribute Instructs the JsonSerializer to always serialize the member with the specified name.
Public class JsonReader Represents a reader that provides fast, non-cached, forward-only access to serialized JSON data.
Public class JsonReaderException The exception thrown when an error occurs while reading JSON text.
Public class JsonRequiredAttribute Instructs the JsonSerializer to always serialize the member, and to require that the member has a value.
Public class JsonSerializationException The exception thrown when an error occurs during JSON serialization or deserialization.
Public class JsonSerializer Serializes and deserializes objects into and from the JSON format. The JsonSerializer enables you to control how objects are encoded into JSON.
Public class JsonSerializerSettings Specifies the settings on a JsonSerializer object.
Public class JsonTextReader Represents a reader that provides fast, non-cached, forward-only access to JSON text data.
Public class JsonTextWriter Represents a writer that provides a fast, non-cached, forward-only way of generating JSON data.
Public class JsonValidatingReader Obsolete.

Represents a reader that provides JsonSchema validation.

Caution note Caution
JSON Schema validation has been moved to its own package. See https://www.newtonsoft.com/jsonschemafor more details.
Public class JsonWriter Represents a writer that provides a fast, non-cached, forward-only way of generating JSON data.
Public class JsonWriterException The exception thrown when an error occurs while writing JSON text.
Interfaces
 InterfaceDescription
Public interface IArrayPool<T> Provides an interface for using pooled arrays.
Public interface IJsonLineInfo Provides an interface to enable a class to return line and position information.
Enumerations
 EnumerationDescription
Public enumeration ConstructorHandling Specifies how constructors are used when initializing objects during deserialization by the JsonSerializer.
Public enumeration DateFormatHandling Specifies how dates are formatted when writing JSON text.
Public enumeration DateParseHandling Specifies how date formatted strings, e.g. "\/Date(1198908717056)\/" and "2012-03-21T05:40Z", are parsed when reading JSON text.
Public enumeration DateTimeZoneHandling Specifies how to treat the time value when converting between string and DateTime.
Public enumerationCode example DefaultValueHandling Specifies default value handling options for the JsonSerializer.
Public enumeration FloatFormatHandling Specifies float format handling options when writing special floating point numbers, e.g. NaN,PositiveInfinity and NegativeInfinity with JsonWriter.
Public enumeration FloatParseHandling Specifies how floating point numbers, e.g. 1.0 and 9.9, are parsed when reading JSON text.
Public enumeration Formatting Specifies formatting options for the JsonTextWriter.
Protected enumeration JsonReader.State Specifies the state of the reader.
Public enumeration JsonToken Specifies the type of JSON token.
Public enumeration MemberSerialization Specifies the member serialization options for the JsonSerializer.
Public enumeration MetadataPropertyHandling Specifies metadata property handling options for the JsonSerializer.
Public enumeration MissingMemberHandling Specifies missing member handling options for the JsonSerializer.
Public enumerationCode example NullValueHandling Specifies null value handling options for the JsonSerializer.
Public enumeration ObjectCreationHandling Specifies how object creation is handled by the JsonSerializer.
Public enumerationCode example PreserveReferencesHandling Specifies reference handling options for the JsonSerializer. Note that references cannot be preserved when a value is set via a non-default constructor such as types that implement ISerializable.
Public enumeration ReferenceLoopHandling Specifies reference loop handling options for the JsonSerializer.
Public enumeration Required Indicating whether a property is required.
Public enumeration StringEscapeHandling Specifies how strings are escaped when writing JSON text.
Public enumeration TypeNameAssemblyFormatHandling Indicates the method that will be used during deserialization for locating and loading assemblies.
Public enumeration TypeNameHandling Specifies type name handling options for the JsonSerializer.
Public enumeration WriteState Specifies the state of the JsonWriter.
 

另外附上 百度AI 文字識別 Json 及其模型類

 圖片

百度AI 識別文字,返回Json結果, 名字隨意.格式建議為 json,如果使用記事本保存,註意編碼格式是 utf-8,因為c# string預設為utf8,不然會亂碼。

{
  "log_id": 3413661945235258919,
  "direction": 0,
  "words_result_num": 2,
  "words_result": [
    {
      "vertexes_location": [
        {
          "y": 81,
          "x": 51
        },
        {
          "y": 81,
          "x": 151
        },
        {
          "y": 103,
          "x": 151
        },
        {
          "y": 103,
          "x": 51
        }
      ],
      "probability": {
        "variance": 0.0,
        "average": 0.999861,
        "min": 0.999627
      },
      "chars": [
        {
          "char": "今",
          "location": {
            "width": 17,
            "top": 83,
            "left": 60,
            "height": 20
          }
        },
        {
          "char": "天",
          "location": {
            "width": 17,
            "top": 83,
            "left": 78,
            "height": 20
          }
        },
        {
          "char": "除",
          "location": {
            "width": 12,
            "top": 83,
            "left": 103,
            "height": 20
          }
        },
        {
          "char": "了",
          "location": {
            "width": 16,
            "top": 83,
            "left": 116,
            "height": 20
          }
        },
        {
          "char": "皮",
          "location": {
            "width": 13,
            "top": 83,
            "left": 140,
            "height": 20
          }
        }
      ],
      "min_finegrained_vertexes_location": [
        {
          "y": 81,
          "x": 51
        },
        {
          "y": 81,
          "x": 151
        },
        {
          "y": 103,
          "x": 151
        },
        {
          "y": 103,
          "x": 51
        }
      ],
      "finegrained_vertexes_location": [
        {
          "y": 81,
          "x": 51
        },
        {
          "y": 81,
          "x": 71
        },
        {
          "y": 81,
          "x": 90
        },
        {
          "y": 81,
          "x": 110
        },
        {
          "y": 81,
          "x": 129
        },
        {
          "y": 81,
          "x": 149
        },
        {
          "y": 81,
          "x": 151
        },
        {
          "y": 91,
          "x": 151
        },
        {
          "y": 100,
          "x": 151
        },
        {
          "y": 103,
          "x": 151
        },
        {
          "y": 103,
          "x": 132
        },
        {
          "y": 103,
          "x": 112
        },
        {
          "y": 103,
          "x": 93
        },
        {
          "y": 103,
          "x": 73
        },
        {
          "y": 103,
          "x": 54
        },
        {
          "y": 103,
          "x": 51
        },
        {
          "y": 93,
          "x": 51
        },
        {
          "y": 84,
          "x": 51
        }
      ],
      "location": {
        "width": 102,
        "top": 81,
        "left": 51,
        "height": 24
      },
      "words": "今天除了皮"
    },
    {
      "vertexes_location": [
        {
          "y": 109,
          "x": 52
        },
        {
          "y": 109,
          "x": 152
        },
        {
          "y": 130,
          "x": 152
        },
        {
          "y": 130,
          "x": 52
        }
      ],
      "probability": {
        "variance": 8E-05,
        "average": 0.9907,
        "min": 0.973259
      },
      "chars": [
        {
          "char": "又",
          "location": {
            "width": 16,
            "top": 111,
            "left": 61,
            "height": 20
          }
        },
        {
          "char": "啥",
          "location": {
            "width": 12,
            "top": 111,
            "left": 85,
            "height": 20
          }
        },
        {
          "char": "也",
          "location": {
            "width": 16,
            "top": 111,
            "left": 98,
            "height": 20
          }
        },
        {
          "char": "沒",
          "location": {
            "width": 15,
            "top": 111,
            "left": 123,
            "height": 20
          }
        },
        {
          "char": "乾",
          "location": {
            "width": 13,
            "top": 111,
            "left": 141,
            "height": 20
          }
        }
      ],
      "min_finegrained_vertexes_location": [
        {
          "y": 109,
          "x": 52
        },
        {
          "y": 109,
          "x": 152
        },
        {
          "y": 130,
          "x": 152
        },
        {
          "y": 130,
          "x": 52
        }
      ],
      "finegrained_vertexes_location": [
        {
          "y": 109,
          "x": 52
        },
        {
          "y": 109,
          "x": 71
        },
        {
          "y": 109,
          "x": 91
        },
        {
          "y": 109,
          "x": 110
        },
        {
          "y": 109,
          "x": 129
        },
        {
          "y": 109,
          "x": 149
        },
        {
          "y": 109,
          "x": 152
        },
        {
          "y": 119,
          "x": 152
        },
        {
          "y": 129,
          "x": 152
        },
        {
          "y": 130,
          "x": 152
        },
        {
          "y": 130,
          "x": 133
        },
        {
          "y": 130,
          "x": 113
        },
        {
          "y": 130,
          "x": 94
        },
        {
          "y": 130,
          "x": 74
        },
        {
          "y": 130,
          "x": 55
        },
        {
          "y": 130,
          "x": 52
        },
        {
          "y": 121,
          "x": 52
        },
        {
          "y": 111,
          "x": 52
        }
      ],
      "location": {
        "width": 102,
        "top": 109,
        "left": 52,
        "height": 22
      },
      "words": "又啥也沒乾"
    }
  ],
  "language": -1
}

對應的模型 ,將 cs 文件,名字  GeneralModel.cs

    /// <summary>
    /// 通用文字識別(含位置版)返回結果
    /// </summary>
    public class GeneralModel
    {
        /// <summary>
        /// 必選
        /// 唯一的log id,用於問題定位
        /// </summary>
        public long log_id { get; set; }
        /// <summary>
        /// 圖像方向,當detect_direction=true時存在。
        /// 非必選
        ///- -1:未定義,
        ///- 0:正向,
        ///- 1: 逆時針90度,
        ///- 2:逆時針180度,
        ///- 3:逆時針270度
        /// </summary>
        public int direction { get; set; }

        /// <summary>
        /// 必選
        /// 識別結果數,表示words_result的元素個數
        /// </summary>
        public int words_result_num { get; set; }

        /// <summary>
        /// 檢測語言 預設值會返回 -1
        /// </summary>
        public string language { get; set; }
        /// <summary>
        /// 定位和識別文字結果數組
        /// </summary>
        public List<Words_result> words_result { get; set; }

        public class Words_result
        {
            /// <summary>
            /// 圖片中文欄位四個頂點位置(矩形範圍)
            /// </summary>
            public List<XY> vertexes_Location { get; set; }
            /// <summary>
            /// 可選
            /// 行置信度信息;如果輸入參數 probability = true 則輸出
            /// </summary>
            public Probability probability { get; set; }
            /// <summary>
            /// 每個字
            /// </summary>
            public List<Chars> chars { get; set; }
            /// <summary>
            /// 最小細粒度頂點坐標
            /// </summary>
            public List<XY> min_finegrained_vertexes_location { get; set; }
            /// <summary>
            /// 細粒度頂點坐標,多邊形
            /// </summary>
            public List<XY> finegrained_vertexes_location { get; set; }
            /// <summary>
            /// 文字在圖片中的相對位置
            /// </summary>
            public Location location { get; set; }
            /// <summary>
            /// 識別出的文字
            /// </summary>
            public string words { get; set; }
            /// <summary>
            /// 坐標
            /// </summary>
            public class XY
            {
                public int x { get; set; }
                public int y { get; set; }
            }
            /// <summary>
            /// 行置信度
            /// </summary>
            public class Probability
            {
                /// <summary>
                /// 行置信度平均值方差
                /// </summary>
                public double variance { get; set; }
                /// <summary>
                /// 行置信度平均值
                /// </summary>
                public double average { get; set; }

                /// <summary>
                /// 行置信度最小值
                /// </summary>
                public double min { get; set; }
            }
            /// <summary>
            /// 單個文字
            /// </summary>
            public class Chars
            {
                /// <summary>
                /// 識別的單個文字
                /// </summary>
                public char chaR { get; set; }
                /// <summary>
                /// 該文字範圍(矩形)
                /// </summary>
                public Location location { get; set; }
            }
        }
        public class Location
        {
            public int left { get; set; }
            public 	   

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

-Advertisement-
Play Games
更多相關文章
  • 什麼是Sql註入?如何避免Sql註入? 用戶根據系統的程式構造非法的參數從而導致程式執行不是程式期望的惡意Sql語句。 使用參數化的Sql就可以避免Sql註入。 資料庫三範式是什麼? 第一範式:欄位不能有冗餘信息,所有欄位都是必不可少的。 第二範式:滿足第一範式並且表必須有主鍵。 第三範式:滿足第二 ...
  • 為了驗證採用dotnet core技術開發的物聯網設備數據採集接入服務應用是否能在高性價比的linux嵌入式平臺運行,針對dotnet core應用程式進行嵌入式linux環境的發佈部署運行驗證研究。 ...
  • 在.net 中類(class) 與結構(Struct)的異同。 Class 可以被實例化,屬於引用類型,是分配在記憶體的堆上的。類是引用傳遞的。 Struct 屬於值類型,是分配在記憶體的棧上的。結構體是複製傳遞的。 Boolean等屬於結構體。 堆和棧的區別 棧是編譯期間就分配好的記憶體空間,因此你的代 ...
  • class Sign_verifySign { #region prepare string to sign. //example format: a=123&b=xxx&c (with sort) private static string encrypt(T body) { var mType ... ...
  • 趁著在放假時候,給大家總結一點筆試面試上的東西,也剛好為年後跳槽做一點小積累。 下麵的參考解答只是幫助大家理解,不用背,面試題、筆試題千變萬化,不要夢想著把題覆蓋了,下麵的題是供大家查漏補缺用的,真正的把這些題搞懂了,才能“以不變應萬變”。回答問題的時候能聯繫做過項目的例子是最好的,有的問題後面我已 ...
  • 索引: 目錄索引 一.組件特性簡介: 1.MSIL 底層代碼採用 System.Reflection.Emit.Lightweight 類庫使用 IL 的方式處理 Model 組裝,性能剛剛的~ 2.API 大量使用 System.Linq.Expressions 方式,強類型,對程式員編碼非常友好 ...
  • 通常 在完成 條件之後再增加分數 所以 一開始先增加 得到分數++; 分數ui.text = 得到分數.ToString(); 下麵是寫貪吃蛇的 ...
  • 一、ViewData 1、ViewData派生自ViewDataDictionary,所以它具有字典的屬性,例如:ContainsKey 、Add 、Remove 和 Clear ; 2、字典鍵值是字元串類型,所以可以帶空格,例如ViewData["a b"]; 3、在視圖中,只有string類型的 ...
一周排行
    -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.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...