我正在尝试将此文本文件转换为 python 字典。
基本格式是
"items_game"
{
"game_info"
{
"first_valid_class" "1"
"last_valid_class" "9"
"first_valid_item_slot" "0"
"last_valid_item_slot" "10"
"num_item_presets" "4"
}
"qualities"
{
"key" "value"
}
...
"community_market_item_remaps"
{
"Supply Crate"
{
"Supply Crate 2" "1"
"Supply Crate 3" "1"
}
"Decoder Ring"
{
"Winter Key" "1"
"Summer Key" "1"
"Naughty Winter Key 2011" "1"
"Nice Winter Key 2011" "1"
"Scorched Key" "1"
"Fall Key 2012" "1"
"Eerie Key" "1"
"Naughty Winter Key 2012" "1"
"Nice Winter Key 2012" "1"
}
}
}
这个文件几乎是一本字典,但不完全是。有没有办法将其转换为字典,以便我可以通过键访问字典的每一级?我想做类似的事情:
foreach key in dictName['items_game']['community_market_item_remaps']['Decoder Ring']:
# do something
感谢您的帮助。