2
リストにネストされたJSON内のすべてのキーの値を抽出します。Pythonは、私は以下のようなJSONを持って
{"widget": {
"debug": "on",
"window": {
"title": "SampleWidget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity/100) * 90;"
}
}}
私は、すべてのキーと値のペアを抽出する必要があります。例えばdebug=on,title=SampleWidget,name=main_window
など。 これを一般的な方法で行うにはどうすればよいですか?私はjsonが例のもの以外のものであってもよいが、手順は同じでなければならないことを意味する。
あなたは値が辞書そのものではないすべてのカップルの辞書が必要ですか? 折りたたみ辞書ですか? それは問題ではないでしょうか?あなたは3つの 'name'キーを持っています – Neo
あなたの答えはここにあります:http://stackoverflow.com/questions/10756427/loop-through-all-nested-dictionary-valuesまたはhere:http://stackoverflow.com/questions/3229419/pretty-printing-nested-dictionaries-in-python –