我正在尝试使用C#的Autodesk forge API获取集线器列表。 这是我迄今所做的: 使用Autodesk Forge API接收集线器列表
HubsApi api = new HubsApi();
Hubs hubs = api.GetHubs();
很简单。但是当我这样做时,我会得到一个例外,抱怨,不能将DynamicJsonResponse
转换为Hubs
。我想,这是因为我在响应字符串中收到两条警告,所以它不再是集线器对象。该警告是这样的:
"warnings":[
{
"Id":null,
"HttpStatusCode":"403",
"ErrorCode":"BIM360DM_ERROR",
"Title":"Unable to get hubs from BIM360DM EMEA.",
"Detail":"You don't have permission to access this API",
"AboutLink":null,
"Source":[
],
"meta":[
]
}
所有这一切都被包装在一个字典有四个条目,其中只有两个是数据。但是,根据Autodesk的说法,这个警告可以忽略。
所以之后,我试图将其转换成一个解释,只选择数据输入
HubsApi api = new HubsApi();
DynamicJsonResponse resp = api.GetHubs();
DynamicDictionary hubs = (DynamicDictionary)resp.Dictionary["data"];
然后,我通过它循环:
for(int i = 0; i < hubs.Dictionary.Count && bim360hub == null; i++)
{
string hub = hubs.Dictionary.ElementAt(i).ToString();
[....]
}
但字符串hub
不一个json-hub。它是一个看起来像这样的数组:
[
0,
{
"type": "hubs",
"id": "****",
"attributes": {...},
"links": {...},
"relationships": {...},
}
]
而数组中的第二个元素是我的集线器。我知道,我如何选择第二个元素。但要获得枢纽清单一定要容易得多。 在引用它seemd与这些代码简单的两行的示例:
HubsApi api = new HubsApi();
Hubs hubs = api.GetHubs();
任何想法,我如何管理让我的枢纽?