反序列化此 JSON 字符串的正确方法是什么?它只是一个字典数组,其中每个字典都有一个“标题”和“子项”,其中子项是另一个字典数组。
我将其用作 TreeView 项目源,但树视图仅显示 Title1 > Child1 因为我认为我正在做的反序列化有问题。我也尝试打印出 Child1 的第一个孩子,但不知道该怎么做。下面的代码有一个无效的强制转换异常。
s = @"[{""title"":""Title1"",""children"":[{""title"":""Child1"",""children"":[{""title"":""grandchild1"",""children"":[{""title"":""Huh""}]}] }] }]";
List<Dictionary<string, object>> marr = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(s);
mTreeView.ItemsSource = marr;
List<Dictionary<string,object>> cs = (List<Dictionary<string,object>>)marr[0]["children"];
Debug.WriteLine(cs[0]["title"]);