1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        Fluent-jsonC# 的 JSON 生成器和解析器

        聯(lián)合創(chuàng)作 · 2023-09-21 21:33

        Fluent-json 是 C# 的 JSON 生成器和解析器,除了支持基本的 JSON 操作,還可以映射自定義類到 JSON 數(shù)據(jù)格式。這是一個線程安全的庫,同時確保強(qiáng)類型安全。

        示例代碼:

        JsonEncoder<Book> encoder = Json.EncoderFor<Book>(config => config
            .MapType<Book>(map => map
        
                .AllFields()
        
                // DateTime can't be encoded to native json. Conversion is required.
                .Field<DateTime>(field => field.pubDate, pubDate => pubDate
                    .EncodeAs<string>(value => value.ToShortDateString())
                )
        
                // BookType can't be encoded either, let's convert it too.
                .Field<BookType>(field => field.type, type => type
                    .EncodeAs<int>(value => (int)value)
                    // Lets assume we would want to encode this field to a
                    // different json field.
                    .To("book_type")
                )
            )
        
            .MapType<Author>(map => map
                .AllFields()
            )
        
            .UseTidy(true)
        );
        
        Book book = new Book();
        book.title = "Around the world in 80 days";
        book.tags = new List<string> { "traveling", "adventure" };
        book.pageCount = 342;
        book.pubDate = DateTime.Now;
        
        book.author = new Author();
        book.author.forname = "Jules";
        book.author.surname = "Verne";
        
        string json = encoder.Encode(book);
        瀏覽 28
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報
        評論
        圖片
        表情
        推薦
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            亚洲午夜福利一区 | 久久久久久久久久久免费视频 | 新婚白嫩饱满的双乳浑圆 | 中文字幕在线无码视频 | 欧美 日韩 中文 | 久久理论电影 | 男人天堂成人网 | 美女无遮挡撒尿 | 国产在线三区 | 久久人人爽人人爽人人片aV东京热 |