当前位置:网站首页>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
边栏推荐
- Path environment variable
- An essay on the classical "tear down the wall in thinking"
- 批量制造测试数据的思路,附源码
- Encapsulating the logging module
- SQL database
- 杂文 谈谈古典的《拆掉思维里的墙》
- Detailed explanation of UWA pipeline function | visual configuration automatic test
- How much do you know about the process of the interview
- Idea of batch manufacturing test data, with source code
- Modify the test case name generated by DDT
猜你喜欢
Phpstudy V8, a commonly used software for station construction 1 graphic installation tutorial (Windows version) super detailed
Mock test
面试百分百问到的进程,你究竟了解多少
Pycham connects to the remote server and realizes remote debugging
人脸识别框架之dlib
Use if else to judge in sail software - use the title condition to judge
feign报400处理
ACL 2022 | dialogved: a pre trained implicit variable encoding decoding model for dialogue reply generation
Use itextpdf to intercept the page to page of PDF document and divide it into pieces
Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme
随机推荐
The new MySQL table has a self increasing ID of 20 bits. The reason is
PHP efficiently reads large files and processes data
◰GL-着色器处理程序封装
深入了解3D模型相关知识(建模、材质贴图、UV、法线),置换贴图、凹凸贴图与法线贴图的区别
Decimal format decimal / datetime conversion processing
SQL database
批量制造测试数据的思路,附源码
Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
【题解】[SHOI2012] 随机树
Camtasia2022软件新增功能介绍
英语 | Day15、16 x 句句真研每日一句(从句断开、修饰)
SQL: How to parse Microsoft Transact-SQL Statements in C# and to match the column aliases of a view
STM32__03—初识定时器
无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
Solution of garbled code on idea console
JMeter installation tutorial and solutions to the problems I encountered
伪分布安装spark
TypeError: set_ figure_ params() got an unexpected keyword argument ‘figsize‘
Multithreaded @ async thread pool
Selenium IDE and XPath installation of chrome plug-in