【问题标题】:Reading part of json into c# object将部分 json 读入 c# 对象
【发布时间】:2019-07-31 21:59:56
【问题描述】:

我有相当大的 json 字符串,我试图在 azure 函数中读取对象的一小部分,但我不知道该怎么做。

链接到示例 json https://docs.microsoft.com/en-us/azure/devops/service-hooks/events?view=azure-devops#workitem.updated

我尝试创建类,但我真的不知道如何从 json 访问“WorkItemType”,因为它看起来嵌套在“字段”中。

我的对象代码

public class jsonObject
    public string System.WorkItemType  { get; set; }
    public string System.State  { get; set; }
}

在这里反序列化

dynamic eventData = await req.Content.ReadAsAsync<jsonObject>();

【问题讨论】:

标签: c# json


【解决方案1】:

试试这个:

public class jsonObject
    public string WorkItemType  { get; set; }
    public string State  { get; set; }
}

反序列化:

jsonObject eventData = await req.Content.ReadAsAsync<jsonObject>();

eventData 对象包含您的数据

【讨论】:

    猜你喜欢
    • 2012-01-15
    • 2014-01-29
    • 2020-05-28
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 2014-04-21
    • 1970-01-01
    相关资源
    最近更新 更多