我想知道是否可以遍历包含Expando对象数组的Expando对象?
我目前正在解析具有以下文件结构的一些JSON:
"event":
[{
"name": "BEGIN!",
"count": 1
}],
"context":
{
"customer": {
"greetings":
[
{ "Value1": "Hello" },
{ "Value2": "Bye" }
],
"nicknames": []
}
}
我可以通过以下方法获取“event”的扩展对象:
GenerateDictionary(((ExpandoObject[])dict["event"])[0], dict, "event_");
这是GenerateDictionary方法的代码:
private void GenerateDictionary(System.Dynamic.ExpandoObject output, Dictionary<string, object> dict, string parent)
{
try
{
foreach (var v in output)
{
string key = parent + v.Key;
object o = v.Value;
if (o.GetType() == typeof(System.Dynamic.ExpandoObject))
{
GenerateDictionary((System.Dynamic.ExpandoObject)o, dict, key + "_");
}
else
{
if (!dict.ContainsKey(key))
{
dict.Add(key, o);
}
}
}
}
catch (Exception ex)
{
WritetoLog(itemname, ex);
}
}
我现在完全不知道如何检索'context_customer_greetings'中的所有值,因为当我尝试下面的操作时,它只会检索到'context_customer_greetings_value1'对象。
GenerateDictionary(((System.Dynamic.ExpandoObject[])dict["context_customer_greetings"])[0], dict, "context_customer_greetings_");
能否遍历ExpandoObject?
希望我的问题表述清晰,谢谢你提前的帮助。