如何使用linq查询C#获取值

问题描述

如何从json下面使用linq查询或lambda表达式获取authRoleCode = AHGENERAL的值。在代码下面,我在此json下面提供了类结构。我曾经这样尝试过。

var str = request.ApplicationsAccess.CategoryAccessType.Where(x=>x.),

如何获取数据数据。

    "applicationsAccess": {
                            "categoryAccessType": [{
                                            "categoryCode": "Accident and Health","basicApplications": {
                                                            "applictaionType": "basicApplications","roleAmpLabelAdded": [{
                                                                            "roleAMPLabel": "General access to marketing & resources","authRoleCode": "AHGENERAL","authRoleName": "A&H - General access to marketing & resources".

这是类结构,我们用于上面的json。

public partial class ApplicationsAccess
    {
        [JsonProperty("categoryAccessType")]
        public List<CategoryAccessTyp> CategoryAccessType { get; set; }
    }

    public partial class CategoryAccessTyp
    {
        [JsonProperty("categoryCode")]
        public string CategoryCode { get; set; }

        [JsonProperty("applicationTypes")]
        public List<ApplicationType> ApplicationTypes { get; set; }
    }

    public partial class ApplicationType
    {
        [JsonProperty("applictaionType")]
        public string ApplictaionType { get; set; }
       
        public List<RoleAmpLabelAdded> RoleAmpLabelAdded { get; set; }
        
        public ApplicationsAdded ApplicationsAdded { get; set; }
    }

    public partial class ApplicationsAdded
    {
        [JsonProperty("applications")]
        public List<Applications> Applications { get; set; }
    }

    

    public partial class RoleAmpLabelAdded
    {
        [JsonProperty("roleAMPLabel")]
        public string RoleAmpLabel { get; set; }

        [JsonProperty("authRoleCode")]
        public string AuthRoleCode { get; set; }

        [JsonProperty("authRoleName")]
        public string AuthRoleName { get; set; }

        [JsonProperty("applications")]
        public List<Applications> Applications { get; set; }
    }
    public partial class Applications
    {
        [JsonProperty("appId")]

        public long AppId { get; set; }

        [JsonProperty("appCode")]
        public long AppCode { get; set; }

        [JsonProperty("appName")]
        public string AppName { get; set; }
    }

如果您需要更多信息,请告诉我们 TIA。

解决方法

如果您需要db.collection.aggregate([{$project: { station:'$station.name',n:{$map: { input:"$samples.data",as:"vals",in: { $size: { "$objectToArray": "$$vals" } } }} }}]) 类的对象,它们的RoleAmpLabelAdded 属性等于AuthRoleCode,则可以尝试以下代码:

"AHGENERAL"

要获取所有 IEnumerable<RoleAmpLabelAdded> result = request .ApplicationAccess .CategoryAccessType .SelectMany(c => c.ApplicationTypes.SelectMany(t => t.RoleAmpLabelAdded)) .Where(r => r.AuthRoleCode == "AHGENERAL"); -s:

AuthRoleCode

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...