通过使用 Microsoft Graph API 5.44,“描述”字段 (item.AdditionalData) 在返回时可以。 如果我使用高于 5.44 的 API,则该字段的值为 Microsoft.Kiota.Abstractions.Serialization.UntypedArray。
这是我的阅读方式...
User.Description = ReadAdditionalValueAttributeRS((Dictionary<string, object>)item.AdditionalData, "description");
部分代码...
try
{
System.Text.Json.JsonElement jo = (System.Text.Json.JsonElement)newProp.Value;
-->> newProp.Value = Microsoft.Kiota.Abstractions.Serialization.UntypedArray
if (jo.ValueKind == System.Text.Json.JsonValueKind.String)
{
sval = jo.GetString();
sResult = sval.Replace(Microsoft.VisualBasic.Constants.vbCrLf, @"\r\n");
break;
}
else if (jo.ValueKind == System.Text.Json.JsonValueKind.Array)
{
var elementContentEnumerator = jo.EnumerateArray();
while (elementContentEnumerator.MoveNext())
{
Console.WriteLine($"You are now at property {elementContentEnumerator.Current}");
sval += elementContentEnumerator.Current.ToString();
sval += " ";
}
sResult = sval.Trim().Replace(Microsoft.VisualBasic.Constants.vbCrLf, @"\r\n");
break;
}
}
可以检查这个值吗?
我当前切换回 Microsoft Graph API 5.44,而该值正常。 我使用版本 5.56、5.57 和 5.58 进行测试。返回值不行。
类
UntypedNode
是UntypedArray
、UntypedString
、UntypedInteger
、UntypedBoolean
等的基类。所有Untyped
类都有GetValue()
方法,该方法返回无类型节点、字符串、int、或布尔值。
检查
newProp.Value
是否为UntypedArray
或UntypedString
,然后使用GetValue()
读取值。
try
{
if (newProp.Value is UntypedString untypedString)
{
sval = untypedString.GetValue();
sResult = sval.Replace(Microsoft.VisualBasic.Constants.vbCrLf, @"\r\n");
break;
}
else if (newProp.Value is UntypedArray untypedArray)
{
foreach (var item in untypedArray.GetValue())
{
if (item is UntypedString itemUntypedString)
{
sval += itemUntypedString.GetValue();
sval += " ";
}
}
sResult = sval.Trim().Replace(Microsoft.VisualBasic.Constants.vbCrLf, @"\r\n");
break;
}
}
恐怕 Graph SDK 团队没有很好地记录与
UntypedNode
的合作。