我的结果集中包含一个 id 字段,该字段来自我存储为动态对象的 Web 响应。{ "filterFields": [ { "connectionName": "metis_dev", "querySourceCategoryName": "dbo", "sourceFieldName": "DealerGroupId", "sourceFieldVisible": true, "sourceFieldFilterable": true, "sourceDataObjectName": "Dealers", "sourceDataObjectFullName": "metis_dev.dbo.Dealers", "querySourceName": "Dealers", "dataType": "Numeric", "isParameter": false, "isCalculated": false, "calculatedTree": null, "compareFieldCalculatedTree": null, "compareValueCalculatedTree": null, "compareField": null, "selected": false, "dataFormat": null, "reportId": null, "useMappedFieldAlias": false, "uniqueId": null, "comparisionValue": null, "inTimePeriodType": null, "valueInTimePeriod": null, "hasModifiedCalculatedTree": false, "isHiddenFilter": false, "isInheritableFilter": false, "isOveridingInheritedFilter": false, "operatorName": "Equals (Manual Entry No Auto-Complete)", "type": 0, "isRunningField": false, "isCompositeField": false, "isDrillDown": false, "originalDataType": null, "isReGroupField": false, "filterId": "3ab260ff-6894-4f23-ab78-5b4db43ae65e", "reportFieldAlias": null, "reportPartTitle": null, "querySourceFieldId": "d313dc65-3d63-4682-8c80-6ab0f235b1d7", "querySourceType": "Table", "querySourceId": "ac13435a-98b1-4ea9-97af-815b67842334", "relationshipId": null, "alias": "DealerGroupId", "position": 1, "visible": true, "required": false, "cascading": true, "operatorId": "5b654e75-d293-4e7e-9102-cdb74286e717", "operatorSetting": null, "value": "4967", "dataFormatId": null, } ]}当我在运行时将鼠标悬停在根对象上时,其中一个值就是上面的filterFields对象。但是当我说 时foreach(var filterField in root.filterFields),我会得到一个错误,因为filterField结果中不存在。我应该如何访问该filterFields集合以便获得我正在寻找的“id”属性?我想filterFields从结果中循环,但我现在无法做到。
1 回答
慕慕森
TA贡献1856条经验 获得超17个赞
想通了这一点。必须将该项目转换为 JToken,这样就完成了。
JObject root= JObject.Parse(item.Root.ToString());
foreach (JToken rootItem in root.SelectToken("filterFields"))
{
var id = rootItem["id"];
}
- 1 回答
- 0 关注
- 101 浏览
添加回答
举报
0/150
提交
取消