0
我無法弄清楚如何使用simplejson來執行嵌套對象訪問。我看過的docs的例子和搜查,但找不到實現以下功能的方法:simplejson嵌套對象索引
nested = json.loads('{ "foo": {"bar": 1}}')
value = nested['foo.bar']
if(value == 1):
print('success')
這將產生以下錯誤:
KeyError: 'foo.bar'
有越來越的方式嵌套的對象,而不必一次訪問一個對象?
「嵌套['foo'] ['bar']'究竟有什麼問題? – 2013-03-26 16:41:13
感謝Martijn,我是python的新手,並沒有意識到字典訪問的語法。這對我的用例來說很好。 – dsimmie 2013-03-26 16:50:22