gpt4 book ai didi

c# - skydrive System.Dynamic.DynamicObject

转载 作者:行者123 更新时间:2023-11-30 15:36:59 26 4
gpt4 key购买 nike

我正在尝试获取 SkyDrive 上登录用户的所有文件夹列表。

LiveOperationResult operationResult = await client.GetAsync("me/skydrive/files");
dynamic result = operationResult.Result;

我希望能够做这样的事情:

Dictionary<string, object> folderData = (Dictionary<string, object>)result;
List<object> folders = (List<object>)folderData["data"];

foreach (object item in folders)
{
Dictionary<string, object> folder = (Dictionary<string, object>)item;
if (folder["name"].ToString() == "Folder Name")
{
showToastMessage(folder["id"].ToString());
return;
}
}

但是,在这一行:

Dictionary<string, object> folderData = (Dictionary<string, object>)result;

我收到一个错误:

Cannot convert type 'System.Dynamic.DynamicObject' to 'System.Collections.Generic.Dictionary'

有人知道我该如何解决这个问题吗?

最佳答案

问题是 LiveOperationResult.Result 不一定保证是 Dictionary<string, object> .然而,它被定义为 IDictionary<string, object> .

请注意,您似乎甚至不需要转换 Result任何类型字典的属性;你应该可以使用 dynamic变量直接访问您要迭代的列表。

List<object> folders = (List<object>)result.data;

关于c# - skydrive System.Dynamic.DynamicObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13150863/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com