1

我有一本这样的字典:

{
  "A" : {
    "A1" : {
      "er" : false,
      "hy" : false,
      "fv" : false,
      "fr" : false
    },
    "A2" : {
      "fr" : false,
      "ty" : false,
      "ty" : false,
    },
  "B" : {
    "B1" : {
      "er" : false,
      "hy" : false,
      "fv" : false,
      "fr" : false
    },
    "B2" : {
      "fr" : false,
      "ty" : false,
      "ty" : false,
    },
  }
}

我正在尝试将 A 和 B 字典的值作为单独的字典检索

我试过了

Dictionary<string, object> dict =
    jss.Deserialize<Dictionary<string, object>>(json);

Dictionary<string, object> dict1 = dict["A"];//error over here

无法将类型“object”隐式转换为“System.Collections.Generic.Dictionary”。存在显式转换(您是否缺少演员表?)

如何解决这个问题?

4

1 回答 1

2

试试这个:

Dictionary<string, Dictionary<string, bool>> dict = 
    jss.Deserialize<Dictionary<string, Dictionary<string, bool>>>(json);
Dictionary<string, bool> dict1 = dict["A"];
于 2012-10-11T12:32:01.463 回答