需要在Python中解释json和dict之间的区别

use*_*557 7 python json dictionary explicit implicit

我只是想要更深入地理解Python中的JSON和Dict.

我有一个来自这样的服务器的JSON响应:

`{"city":"Mississauga","country":"Canada","countryCode":"CA"}`
Run Code Online (Sandbox Code Playgroud)

我想把它作为一本字典来处理.为此,我使用.json()函数.为什么我可以通过使用获取数据res.json()['city'],但不能用它来做req.json().city

2Cu*_*bed 10

在Python中,无法使用my_dict.key语法访问字典值.这是为dict类的属性保留的,例如dict.getdict.update.字典值只能通过my_dict[key]语法访问.