이 text 파일을 파이썬 사전으로 변환하려고합니다.웹 호출을 통해 수신 된 텍스트 파일을 사전으로 변환하려면 어떻게해야합니까?
기본 형식은 아니지만 확실히,이 파일은 거의 사전입니다
"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
감사합니다.
()는 외부 소스로부터 데이터를 실행하는 평가()을 방지한다. 나는이 접근법을 좋아한다. – Neil