当前位置:网站首页>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
边栏推荐
猜你喜欢
LVM与磁盘配额
Zhongang Mining: Fluorite Flotation Process
Modify the test case name generated by DDT
English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)
True math problems in 1959 college entrance examination
Disk management and file system
Project framework of robot framework
1959年高考数学真题
ByteVCharts可视化图表库,你想要的我都有
oracle 中快速获取表的列名列表
随机推荐
如何用Redis实现分布式锁?
Take according to the actual situation, classify and summarize once every three levels, and see the figure to know the demand
信息摘要、数字签名、数字证书、对称加密与非对称加密详解
Change the password after installing MySQL in Linux
Encapsulating the logging module
Cartoon: what are IAAs, PAAS, SaaS?
STM32__03—初识定时器
◰ GL shadow map core steps
ByteVCharts可视化图表库,你想要的我都有
关于 background-image 渐变gradient()那些事!
UWA Pipeline 功能详解|可视化配置自动测试
英语 | Day15、16 x 句句真研每日一句(从句断开、修饰)
Detailed explanation of file operation (2)
Decimal format decimal / datetime conversion processing
Detailed explanation of the penetration of network security in the shooting range
Talk about browser cache control
Creation of RAID disk array and RAID5
Selenium IDE and XPath installation of chrome plug-in
[pimf] openharmony paper Club - what is the experience of wandering in ACM survey
Linux MySQL data timing dump