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