我在尝试访问嵌套Dictionary
时遇到问题,似乎返回nil
。
以下是info
类型Dictionary<String, Any>
的输出:
info = ["list_order": 1, "name": Some Text, "id": 1, "menu_items": {
1 = {
"food_name" = "String";
"food_picture" = "link";
"food_price" = "2.00";
};
2 = {
"food_name" = "String";
"food_picture" = "link";
"food_price" = "5.00";
id = 2;
};
}]
info["menu_items"]
的输出:
info["menu_items"] = {
1 = {
"food_name" = "String";
"food_picture" = "link";
"food_price" = "2.00";
id = 1;
};
2 = {
"food_name" = "String";
"food_picture" = "link";
"food_price" = "5.00";
id = 2;
};
}
但是,以下分配会在nil
中生成test
:
let test = info["menu_items"] as? Dictionary<Int, Any>
是否有不明显的事情或我不理解基本原理?