【发布时间】:2020-12-31 21:03:49
【问题描述】:
如何使用 linq 查询或 lambda 表达式从 json 下面获取 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。
【问题讨论】:
-
request对象是什么?是否将 JSON 解析为对象模型?而且我不太明白什么是行不通的。您能否提供您正在做什么的代码,request对象是如何初始化的。此外,如果您也可以提供错误消息,那就太好了。 -
@E.Shcherbo 我添加了类结构。
-
谢谢。你究竟需要得到什么?
RoleAmpLabelAdded类的对象AuthRoleCode等于"AHGENERAL"? -
@E.Shcherbo 是的