我的应用程序中有以下 JSON。
string json = @"{""dest"":[ { ""mode"": ""1"", ""test"":""test1,test,test2""},{ ""mode"": ""2"", ""test"": ""test3"" }]}";
使用以下方法获取dest I m的值。
var json_serializer = new JavaScriptSerializer();
Dictionary<string, object> dictionary = json_serializer.Deserialize<Dictionary<string, object>>(json);
public Dictionary<string, object> GetObject(Dictionary<string, object> view, string name)
{
Dictionary<string, object> result = new Dictionary<string, object>();
object value = null;
foreach (KeyValuePair<string, object> pair in view)
{
Type type = pair.Value.GetType();
if (pair.Key == name)
{
**Dictionary<string, object> child = (System.Collections.Generic.Dictionary<string, object>)pair.Value;**
result = GetObject(child, name);
if (result != null)
{
break;
}
}
else
{
}
}
return result;
}
我在 Dictionary child = (System.Collections.Generic.Dictionary)pair.Value;行中遇到错误 . 错误提示“无法将 'System.Collections.ArrayList' 类型的对象转换为 'System.Collections.Generic.Dictionary`2[System.String,System.Object]'。”
任何人都知道如何解决这个问题?