0

我正在尝试获取用户拥有的所有日历。我正在使用的代码是:

LiveConnectClient liveClient = new LiveConnectClient( App.Session );
LiveOperationResult operationResult = await liveClient.GetAsync( "me/calendars" );
dynamic result = operationResult.Result; 

当使用调试器查看结果时,我可以看到日历(键和值)。但是,我在从此 DynamicDictionary 中提取信息时遇到问题。

4

2 回答 2

0

它只是一本字典。你应该能够做到:

var item = result[key];
于 2012-11-14T22:10:46.003 回答
0

我设法解决了这个问题,执行它的代码(带有一些调试消息)如下:

try
{
    LiveConnectClient liveClient = new LiveConnectClient( App.Session );
    LiveOperationResult operationResult = await liveClient.GetAsync( "me/calendars" );
    dynamic result = operationResult.Result;

    List<object> data = null;
    IDictionary<string, object> calendar = null;

    string msg = "Calendar names: ";
    Debug.WriteLine( msg );

    if ( operationResult.Result.ContainsKey( "data" ) )
    {
        data = (List<object>)operationResult.Result[ "data" ];
        for ( int i = 0 ; i < data.Count ; i++ )
        {
            calendar = (IDictionary<string, object>)data[ i ];
            if ( calendar.ContainsKey( "name" ) )
            {
                string Name = (string)calendar[ "name" ];
                string ID   = (string)calendar[ "id" ];
                msg = string.Format( "Name = {0}, ID = {1}", Name, ID );
                Debug.WriteLine( msg );
            }
        }
    }
}
catch ( LiveConnectException exception )
{
    Debug.WriteLine( "Error getting calendar info: " + exception.Message );
}
于 2012-11-15T06:37:01.573 回答