当前位置:网站首页>json反序列化匿名数组/对象
json反序列化匿名数组/对象
2022-04-23 13:59:00 【流苏1990】
1、反序列化匿名数组
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、反序列化匿名对象
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的情况下:
/// <summary>
/// 反序列化为匿名对象
/// </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>
/// 反序列化为匿名对象
/// </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);
}
版权声明
本文为[流苏1990]所创,转载请带上原文链接,感谢
https://blog.csdn.net/fuweiping/article/details/122210928
边栏推荐
- Reading notes: fedgnn: Federated graph neural network for privacy preserving recommendation
- JUC interview questions about synchronized, ThreadLocal, thread pool and atomic atomic classes
- JS force deduction brush question 103 Zigzag sequence traversal of binary tree
- 1256:献给阿尔吉侬的花束
- Question bank and answer analysis of the 2022 simulated examination of the latest eight members of Jiangxi construction (quality control)
- [code analysis (5)] communication efficient learning of deep networks from decentralized data
- Analysis of cluster component gpnp failed to start successfully in RAC environment
- Reading notes: meta matrix factorization for federated rating predictions
- Choreographer full resolution
- JS force deduction brush question 102 Sequence traversal of binary tree
猜你喜欢
淘宝发布宝贝提示“您的消保保证金额度不足,已启动到期保障”
elmo(BiLSTM-CRF+elmo)(Conll-2003 命名实体识别NER)
2021年秋招,薪资排行NO
Postman reference summary
Handling of high usage of Oracle undo
Leetcode brush question 𞓜 13 Roman numeral to integer
Oracle告警日志alert.log和跟踪trace文件中文乱码显示
Small case of web login (including verification code login)
Express②(路由)
解决方案架构师的小锦囊 - 架构图的 5 种类型
随机推荐
剑南春把文字游戏玩明白了
try --finally
Decentralized Collaborative Learning Framework for Next POI Recommendation
STM32学习记录0007——新建工程(基于寄存器版)
Technologie zéro copie
Strange bug of cnpm
Android篇:2019初中级Android开发社招面试解答(中
Es introduction learning notes
Express②(路由)
FDFS start
JMeter pressure test tool
UNIX final exam summary -- for direct Department
Quartus Prime硬件实验开发(DE2-115板)实验二功能可调综合计时器设计
【vmware】vmware tools 地址
Leetcode | 38 appearance array
[code analysis (4)] communication efficient learning of deep networks from decentralized data
Port occupied 1
联想产品经理林林:天津当地网络运营商网络故障 ZUI系统后台服务器暂时无法正常工作
Analysis of the problem that the cluster component GIPC in RAC environment cannot correctly identify the heartbeat network state
自动化的艺术