当前位置:网站首页>[original] use system Text. JSON formats the JSON string
[original] use system Text. JSON formats the JSON string
2022-04-23 08:48:00 【Miss Zhao Qingming】
Newtonsoft.Json Although it is widely used , Powerful , But in .NET Core Need to import .
and System.Text.Json It belongs to Microsoft .NET Core Official package in , Compared with Newtonsoft.Json Come on , It's a streamlined package .
In especial Newtonsoft.Json After the author joined Microsoft , The efficiency of Microsoft's official package has far exceeded Newtonsoft.Json package .
therefore , In development , Use as much as possible System.Text.Json, Must pass this thing is Microsoft's own son .
On one JSON When formatting strings , Use System.Text.Json It's also very simple. , But pay attention to coding .
As shown below , To a JSON The string is simply formatted .
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Unicode;
string a = "{\"code\":10000,\"message\":\"ok\",\"description\":\"api The request is successful \",\"uuid\":\"792915a539b84391a868bdf34ace4269\",\"result\":{\"page\":1,\"per\":10,\"total\":1,\"max_page\":1,\"data_struct\":{\"ID\":\" Primary key ID\",\"KZT\":\" Card status (1 normal , Other abnormal )\",\"YKTKH\":\" All in one card number \",\"KWLH\":\" Card physical number \",\"XM\":\" full name \",\"BH\":\" Number ( Student number or faculty number )\",\"YKTZHLXM\":\" All in one card account type code \",\"GQRQ\":\" Expiration date \",\"XGSJ\":\" Modification time \",\"TSTAMP\":\" Time stamp \",\"DWDM\":\" Unit code \",\"DWMC\":\" Name of the company \",\"SFZJH\":\" Id card number \",\"LSDWH\":\" Subordinate unit no \",\"DWLBM\":\" Unit category code \",\"DWLBMC\":\" Unit category name \",\"XBM\":\" Gender code \",\"DQZT\":\" Current status of personnel \",\"BJM\":\" Class code \"}}}";
var jsonDocument =JsonDocument.Parse(a);
var formatJson = JsonSerializer.Serialize(jsonDocument, new JsonSerializerOptions()
{
// Neat printing
WriteIndented = true,
// Recode , Solve the problem of Chinese garbled code
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
});
// Format output
Console.WriteLine(formatJson);
The output is as follows , Finished formatting :
{
"code": 10000,
"message": "ok",
"description": "api The request is successful ",
"uuid": "792915a539b84391a868bdf34ace4269",
"result": {
"page": 1,
"per": 10,
"total": 1,
"max_page": 1,
"data_struct": {
"ID": " Primary key ID",
"KZT": " Card status (1 normal , Other abnormal )",
"YKTKH": " All in one card number ",
"KWLH": " Card physical number ",
"XM": " full name ",
"BH": " Number ( Student number or faculty number )",
"YKTZHLXM": " All in one card account type code ",
"GQRQ": " Expiration date ",
"XGSJ": " Modification time ",
"TSTAMP": " Time stamp ",
"DWDM": " Unit code ",
"DWMC": " Name of the company ",
"SFZJH": " Id card number ",
"LSDWH": " Subordinate unit no ",
"DWLBM": " Unit category code ",
"DWLBMC": " Unit category name ",
"XBM": " Gender code ",
"DQZT": " Current status of personnel ",
"BJM": " Class code "
}
}
}
版权声明
本文为[Miss Zhao Qingming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230846391916.html
边栏推荐
- 完全二叉搜索树 (30 分)
- 2021李宏毅机器学习之Adaptive Learning Rate
- cadence的工艺角仿真、蒙特卡洛仿真、PSRR
- PCTP考试经验分享
- STM32 uses Hal library. The overall structure and function principle are introduced
- 玩转二叉树 (25 分)
- Learn SQL injection in sqli liabs (Level 11 ~ level 20)
- 'bully' Oracle enlarged its move again, and major enterprises deleted JDK overnight...
- Failed to prepare device for development
- 增强现实技术是什么?能用在哪些地方?
猜你喜欢
企业微信应用授权/静默登录
爬虫使用xpath解析时返回为空,获取不到相应的元素的原因和解决办法
Star Trek's strong attack opens the dream linkage between metacosmic virtual reality
Cadence process angle simulation, Monte Carlo simulation, PSRR
Harbor企业级镜像管理系统实战
RCC introduction of Hal Library
Enterprise wechat application authorization / silent login
IDEA导入commons-logging-1.2.jar包
调包求得每个样本的k个邻居
ONEFLOW learning notes: from functor to opexprinter
随机推荐
深度学习框架中的自动微分及高阶导数
Notes d'apprentissage oneflow: de functor à opexprinterpreter
Summary of solid problems
Star Trek's strong attack opens the dream linkage between metacosmic virtual reality
Anonymous type (c Guide Basics)
四张图弄懂matplotlib的一些基本用法
Learn SQL injection in sqli liabs (Level 11 ~ level 20)
洋桃電子STM32物聯網入門30步筆記一、HAL庫和標准庫的區別
爬虫使用xpath解析时返回为空,获取不到相应的元素的原因和解决办法
Navicat remote connection MySQL
Get the absolute path of the class according to the bytecode
okcc呼叫中心外呼系统智能系统需要用多大的盘存录音?
Go语言自学系列 | golang结构体作为函数参数
ONEFLOW learning notes: from functor to opexprinter
关于数组复制问题
OneFlow学习笔记:从Functor到OpExprInterpreter
uni-app和微信小程序中的getCurrentPages()
MySQL查询两张表属性值非重复的数据
Judgment on heap (25 points) two insertion methods
Introduction to matlab