当前位置:网站首页>[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
边栏推荐
- OneFlow學習筆記:從Functor到OpExprInterpreter
- 正点原子携手OneOS直播 OneOS系统教程全面上线
- 'bully' Oracle enlarged its move again, and major enterprises deleted JDK overnight...
- Enterprise wechat application authorization / silent login
- Kubernetes如何使用harbor拉去私有镜像
- Reference passing 1
- Restore binary tree (25 points)
- PLC的点表(寄存器地址和点表定义)破解探测方案--方便工业互联网数据采集
- xctf刷题小记
- synchronized 锁的基本用法
猜你喜欢
洋桃电子STM32物联网入门30步笔记一、HAL库和标准库的区别
bashdb下载安装
Consensus Token:web3.0生态流量的超级入口
L2-022 rearrange linked list (25 points) (map + structure simulation)
四张图弄懂matplotlib的一些基本用法
1099 建立二叉搜索树 (30 分)
Star Trek强势来袭 开启元宇宙虚拟与现实的梦幻联动
2022-04-22 OpenEBS云原生存储
Virtual online exhibition - Online VR exhibition hall realizes 24h immersive exhibition viewing
php基于哈希算法出现的强弱比较漏洞
随机推荐
洋桃电子STM32物联网入门30步笔记一、HAL库和标准库的区别
Go语言自学系列 | golang方法
Idea import commons-logging-1.2 Jar package
okcc呼叫中心外呼系统智能系统需要用多大的盘存录音?
Latex paper typesetting operation
经典题目刷一刷
Reference passing 1
Talent Plan 学习营初体验:交流+坚持 开源协作课程学习的不二路径
Introduction to matlab
HAL库的RCC简介
Judgment on heap (25 points) two insertion methods
LaTeX数学公式
BK3633 规格书
2022-04-22 OpenEBS云原生存储
洋桃电子STM32物联网入门30步笔记四、工程编译和下载
洋桃电子STM32物联网入门30步笔记二、CubeIDE下载、安装、汉化、设置
Restore binary tree (25 points)
《深度学习》学习笔记(八)
Please arrange star trek in advance to break through the new playing method of chain tour, and the market heat continues to rise
正点原子携手OneOS直播 OneOS系统教程全面上线