Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用linq查询C获取值#_Linq_C# 4.0 - Fatal编程技术网

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

如何使用linq查询C获取值#,linq,c#-4.0,Linq,C# 4.0,如何从下面的json中使用linq查询或lambda表达式获取authRoleCode=AHGENERAL的值。在代码下面,我提供了这个json下面的类结构。我试过这样做 var str = request.ApplicationsAccess.CategoryAccessType.Where(x=>x.), 如何获取它的数据 "applicationsAccess": { "category

如何从下面的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; }
    }
公共部分类应用程序访问
{
[JsonProperty(“categoryAccessType”)]
公共列表类别访问类型{get;set;}
}
公共部分类CategoryAccessTyp
{
[JsonProperty(“类别代码”)]
公共字符串类别代码{get;set;}
[JsonProperty(“应用程序类型”)]
公共列表应用程序类型{get;set;}
}
公共部分类应用程序类型
{
[JsonProperty(“applictaionType”)]
公共字符串ApplictaionType{get;set;}
公共列表roleamplabelated{get;set;}
公共应用程序已添加应用程序已添加{get;set;}
}
已添加公共部分类应用程序
{
[JsonProperty(“应用程序”)]
公共列表应用程序{get;set;}
}
公共部分类roleamplabelated
{
[JsonProperty(“roleAMPLabel”)]
公共字符串RoleAmpLabel{get;set;}
[JsonProperty(“authRoleCode”)]
公共字符串AuthRoleCode{get;set;}
[JsonProperty(“authRoleName”)]
公共字符串AuthRoleName{get;set;}
[JsonProperty(“应用程序”)]
公共列表应用程序{get;set;}
}
公共部分类应用程序
{
[JsonProperty(“appId”)]
公共长AppId{get;set;}
[JsonProperty(“appCode”)]
公共长AppCode{get;set;}
[JsonProperty(“appName”)]
公共字符串AppName{get;set;}
}
如果您需要更多信息,请告诉我们
TIA.

如果您需要
roleamplabelated
类的对象,这些对象的
AuthRoleCode
属性等于
“AHGENERAL”
,那么您可以尝试以下代码:

 IEnumerable<RoleAmpLabelAdded> result = request
            .ApplicationAccess
            .CategoryAccessType
            .SelectMany(c => c.ApplicationTypes.SelectMany(t => t.RoleAmpLabelAdded))
            .Where(r => r.AuthRoleCode == "AHGENERAL");

什么是
请求
对象?是否将JSON解析为对象模型?我不太明白到底是什么不起作用。请提供您正在做的工作的代码,以及
请求
对象是如何初始化的。此外,如果您还可以提供一条错误消息,那将非常好。@E.Shcherbo我已经添加了类结构。谢谢。你到底需要什么?
roleamplabelated
类的对象具有
AuthRoleCode
等于
“AHGENERAL”
?@E.Shcherbo yesThanks以获取答案。我们可以获取所有的AuthRoleCode吗?当然,您只需再次调用
Select
。我将更新我的答案。我希望所有的authrole代码不象AuthRoleCode==“AHGENERAL”。@Sam这有帮助吗?
       IEnumerable<string> result = request
            .ApplicationAccess
            .CategoryAccessType
            .SelectMany(c => c.ApplicationTypes.SelectMany(t => t.RoleAmpLabelAdded))
            .Select(r => r.AuthRoleCode);