c# - 按键将 JSON 反序列化为 C# 对象
问题描述
我正在寻找一种反序列化 JSON 的方法,但有些键应该是值,这就是它变得棘手的地方。我喜欢反序列化为:
int valuetoExtract1
int valuetoExtract2
int valuetoExtract3
JSON 看起来像这样:
{
"option1": "someOption1",
"option12": "someOption2",
"id": [
"12345"
],
"filter": "someFilter",
"actualValues": [
{
"otherId": 24,
"id": 12345,
"valuetoExtract1": "123"
},
{
"otherId": 24,
"id": 12345,
"valuetoExtract2": "234"
},
{
"otherId": 24,
"id": 12345,
"valuetoExtract3": "345"
}
]
}
解决方案
你能试试这个:
public class ActualValue
{
public int otherId { get; set; }
public int id { get; set; }
public string valuetoExtract1 { get; set; }
public string valuetoExtract2 { get; set; }
public string valuetoExtract3 { get; set; }
}
public class RootObject
{
public string option1 { get; set; }
public string option12 { get; set; }
public List<string> id { get; set; }
public string filter { get; set; }
public List<ActualValue> actualValues { get; set; }
}
推荐阅读
- unity3d - Unity-如何创建对话树?
- ios - Firestore/Swift 4:检查用户名是否存在?
- amazon-web-services - 图形数据库是否适合此类数据
- java - MediaMetadataRetriever:尝试使用 url 从 mp3 检索专辑封面时应用程序崩溃
- android - 使用 retrofit2 发布 Soap XML 请求(不推荐使用简单 XML 框架)
- c# - SSIS:无法在 DontSaveSensitive 模式下使用 GetSensitiveValue() 访问脚本任务中的敏感参数
- postgresql - 函数返回具有动态列名的行集
- python - 了解对 NumPy 数组执行条件索引时出现的 DeprecationWarning 错误(版本 1.11.13,Python 2.7)
- sql - 将sql表列数据类型从smallmoney更改为money的影响
- django - Django:如何区分用户是从 social_auth 还是本地 Django 用户登录