当前位置:网站首页>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
边栏推荐
- Production environment——
- [pimf] openharmony paper Club - what is the experience of wandering in ACM survey
- Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
- Detailed explanation of Niuke - Gloves
- Cartoon: what are IAAs, PAAS, SaaS?
- Modify the test case name generated by DDT
- About background image gradient()!
- Flask如何在内存中缓存数据?
- Paging the list collection
- PostgreSQL column storage and row storage
猜你喜欢

Path environment variable

【PIMF】OpenHarmony啃论文俱乐部—在ACM Survey闲逛是什么体验

Use if else to judge in sail software - use the title condition to judge

Nacos detailed explanation, something

Detailed explanation of file operation (2)

Pycham connects to the remote server and realizes remote debugging

New project of OMNeT learning

Rtklib 2.4.3 source code Notes

loggie 源码分析 source file 模块主干分析

org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su
随机推荐
Xinwangda: HEV and Bev super fast charging fist products are shipped on a large scale
STM32__ 03 - beginner timer
◰GL-着色器处理程序封装
【PIMF】OpenHarmony啃论文俱乐部—在ACM Survey闲逛是什么体验
杂文 谈谈古典的《拆掉思维里的墙》
_ Mold_ Board_
Smart doc + Torna generate interface document
PyTorch:train模式与eval模式的那些坑
MySQL master-slave synchronization pit avoidance version tutorial
Blue Bridge Cup provincial road 06 -- the second game of the 12th provincial competition
Public variables of robotframework
如何建立 TikTok用户信任并拉动粉丝增长
Pycham connects to the remote server and realizes remote debugging
聊一聊浏览器缓存控制
Modify the test case name generated by DDT
About background image gradient()!
人脸识别框架之dlib
Loading order of logback configuration file
BUG_ me
Cartoon: what are IAAs, PAAS, SaaS?