我有一个来自url的json文件,我想在json中得到key'OnePie_key'的值
import requests
hosturl = requests.get(url='http://api.jsoneditoronline.org/v1/docs/abf48114b71a43f380cd114d37a4bb9d')
print(hosturl.json(['OnePie_KEY']))
但它不起作用
我的Json来自URL
{"name":"Kisame","schema":{"type":"NONE","url":null,"id":null,"content":null,"leftPanel":false,"rightPanel":false},"updated":"2021-09-19T16:47:45.419Z","_rev":33,"_id":"abf48114b71a43f380cd114d37a4bb9d","data":"{\n \"HWID\": {\n \"000001\": [\n \"Riici\",\n \"xx399\",\n \"\",\n 1\n ]\n },\n \"OnePie_KEY\": \"112233445566778899\",\n \"MD5\": \"121321312514654665\"\n}"}
我想阅读键“OnePie_key”中的值,非常感谢您的帮助
代码的前两行工作正常:
您的
hosturl
变量现在包含许多有用的信息还有
.json()
方法,它将.text
属性读取为JSON,实际上是将其转换为Python dict和list检查['data']键,我们可以看到它的内容仍然是一个字符串,而不是一个对象
我们在
json
模块中使用loads()
(加载字符串)方法来转换此字符串:相关问题 更多 >
编程相关推荐