当前位置:网站首页>JSON deserialize anonymous array / object
JSON deserialize anonymous array / object
2022-04-23 16:54:00 【Tassel 1990】
1、 Deserialize anonymous arrays
var result = "{\"batchNum\":\"20211130042359542\",\"responseStatus\":\"SUCCESS\",\"responseMessage\":null,\"executeResult\":\"SUCCESS\",\"restResponseDtlDTOList\":[{\"documentId\":null,\"documentCode\":\"CG080120211126002\",\"responseStatus\":\"SUCCESS\",\"responseMessage\":null},{\"documentId\":null,\"documentCode\":\"CG080120211129002\",\"responseStatus\":\"SUCCESS\",\"responseMessage\":null}]}";
JObject jsonObject = result.ToJObject();
var responseList = "{\"restResponseDtlDTOList\":" + jsonObject["restResponseDtlDTOList"].ToString() + "}";
var definition = new { restResponseDtlDTOList = new[] { new { documentID = "", documentCode = "", responseStatus = "", responseMessage = "" } } };
var encryptObject = JsonConvert.DeserializeAnonymousType(responseList, definition);
var ssss = "";
foreach (var responseItem in encryptObject.restResponseDtlDTOList)
{
if (responseItem.responseStatus.Equals("SUCCESS", StringComparison.OrdinalIgnoreCase))
continue;
ssss = "werwerwer";
}
System.Diagnostics.Debug.Write(ssss);
2、 Deserializing anonymous objects
var definition = new { Name = "", Age = 0, Major = "" };
string json1 = @"{'Name':'GongHui','Age':28,'Major':'.NET ENGINEER'}";
var person1 = JsonConvert.DeserializeAnonymousType(json1, definition);
3、System.Text.Json Under the circumstances :
/// <summary>
/// Deserialize to anonymous object
/// </summary>
/// <returns></returns>
[return: MaybeNull]
public static T DeserializeAnonymousType<T>(string json, T anonymousTypeObject, JsonSerializerOptions? options = null)
{
return JsonSerializer.Deserialize<T>(json, options: options);
}
/// <summary>
/// Deserialize to anonymous object
/// </summary>
/// <returns></returns>
[return: MaybeNull]
public static IEnumerable<T> DeserializeListAnonymousType<T>(string json, T anonymousTypeObject, JsonSerializerOptions? options = null)
{
return JsonSerializer.Deserialize<List<T>>(json, options: options);
}
版权声明
本文为[Tassel 1990]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231359253231.html
边栏推荐
- Loggie source code analysis source file module backbone analysis
- Knowledge points and examples of [seven input / output systems]
- Set cell filling and ranking method according to the size of the value in the soft report
- Detailed explanation of Niuke - Gloves
- 扫码登录的原理你真的了解吗?
- Easyexcel reads the geographical location data in the excel table and sorts them according to Chinese pinyin
- [pimf] openharmony paper Club - what is the experience of wandering in ACM survey
- websocket
- MySql主从复制
- Quick install mongodb
猜你喜欢
NVIDIA显卡驱动报错
File upload and download of robot framework
Set cell filling and ranking method according to the size of the value in the soft report
Detailed explanation of Niuke - Gloves
Do you really understand the principle of code scanning login?
oracle 中快速获取表的列名列表
Project framework of robot framework
STM32__ 03 - beginner timer
English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)
ACL 2022 | DialogVED:用于对话回复生成的预训练隐变量编码-解码模型
随机推荐
Loggie source code analysis source file module backbone analysis
DDT + Excel for interface test
ACL 2022 | DialogVED:用于对话回复生成的预训练隐变量编码-解码模型
RAID磁盘阵列与RAID5的创建
Multithreaded @ async thread pool
Phpstudy V8, a commonly used software for station construction 1 graphic installation tutorial (Windows version) super detailed
Paging the list collection
网络安全之渗透靶场实战详解
Deeply understand the relevant knowledge of 3D model (modeling, material mapping, UV, normal), and the difference between displacement mapping, bump mapping and normal mapping
Use itextpdf to intercept the page to page of PDF document and divide it into pieces
Use case labeling mechanism of robot framework
关于 background-image 渐变gradient()那些事!
The font of the soft cell changes color
批量制造测试数据的思路,附源码
伪分布安装spark
Nifi fast installation and file synchronization
Project framework of robot framework
MySQL master-slave configuration under CentOS
NVIDIA显卡驱动报错
计算饼状图百分比