当前位置:网站首页>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
边栏推荐
- Jiannanchun understood the word game
- [code analysis (2)] communication efficient learning of deep networks from decentralized data
- Quartus Prime硬件实验开发(DE2-115板)实验二功能可调综合计时器设计
- Android 面试主题集合整理
- Record a strange bug: component copy after cache component jump
- 第十五章 软件工程新技术
- Problems encountered in the project (V) understanding of operating excel interface poi
- Search ideas and cases of large amount of Oracle redo log
- 服务器中挖矿病毒了,屮
- scikit-learn構建模型的萬能模板
猜你喜欢
![Special test 05 · double integral [Li Yanfang's whole class]](/img/af/0d52a6268166812425296c3aeb8f85.png)
Special test 05 · double integral [Li Yanfang's whole class]

解决方案架构师的小锦囊 - 架构图的 5 种类型

Multithreading
![MySQL [acid + isolation level + redo log + undo log]](/img/52/7e04aeeb881c8c000cc9de82032e97.png)
MySQL [acid + isolation level + redo log + undo log]

OSS cloud storage management practice (polite experience)

JUC interview questions about synchronized, ThreadLocal, thread pool and atomic atomic classes

Pytorch 经典卷积神经网络 LeNet

SQL learning window function

专题测试05·二重积分【李艳芳全程班】

1256:献给阿尔吉侬的花束
随机推荐
Android篇:2019初中级Android开发社招面试解答(中
联想产品经理林林:天津当地网络运营商网络故障 ZUI系统后台服务器暂时无法正常工作
cnpm的诡异bug
crontab定时任务输出产生大量邮件耗尽文件系统inode问题处理
STM32学习记录0007——新建工程(基于寄存器版)
Business case | how to promote the activity of sports and health app users? It is enough to do these points well
项目中遇到的问题(五)操作Excel接口Poi的理解
Analysis and understanding of atomicintegerarray source code
Choreographer full resolution
[code analysis (1)] communication efficient learning of deep networks from decentralized data
Wechat applet
Using Jupiter notebook in virtual environment
Apache Atlas Compilation and installation records
Crontab timing task output generates a large number of mail and runs out of file system inode problem processing
第十五章 软件工程新技术
Haruki Murakami -- Excerpt from "what do I talk about when I talk about running"
Troubleshooting of expdp export error when Oracle table has logical bad blocks
Record a strange bug: component copy after cache component jump
基础知识学习记录
elmo(BiLSTM-CRF+elmo)(Conll-2003 命名实体识别NER)