如何解决如何使用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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。