【发布时间】:2021-06-10 02:28:35
【问题描述】:
我得到一个嵌套的 Json 作为请求响应,试图精确到 name 字段。然而,在将其转换为 Json 之后,本应是字典的内容变成了字符串。您能否帮助指出我做错了什么以及如何处理?非常感谢。
来自打印response.json()的示例结果:
{'subject': 'order', 'id':20, 'info':{"result":"record","name":"orderrecords", "items":[{"name":"apple","type":"food"},{"name":"orange","type":"food"}]}
我试过了:
response= requests.get("url")
info= response.json()
print (type(info["items"]) #it is str here
我想要实现的是拥有一个值为“名称”的字典,其中包含项目的字典作为键,而“类型”作为值。比如 {"apple":"food", "orange": "food"}
【问题讨论】:
-
你提供了无效的 json
标签: python json python-3.x dictionary python-requests