![](/img/trans.png)
[英]How do I transfer json objects into an excel file using python?
[英]How do I pull objects from a JSON file using python?
目前將 VSCode 與 Jupyter Notebook 一起使用,我正在使用對 HTTP URL 的獲取請求,我能夠獲取數據並在控制台中打印它,我如何提取 ZA8CFDE63311BD59EB2AC96B8 和打印?
import requests
import json
requests.urllib3.disable_warnings()
## API Request to test server ##
response_API = requests.get('https://test.com:8080/exports', auth=('test', 'test1234'), verify=False)
##Printing of JSON ##
pretty_response = json.dumps(response_API.json(), indent=4)
print(pretty_response)
當我打印時,我可以看到所有 JSON 信息,如何提取我想要的字段並打印? 由於某種原因,r.json 在 VSCode 中不起作用。 我需要打印客戶和路徑。 下面的示例花絮。
{
"digest": "1234121234",
"exports": [
{
"clients": [
"tester1.com",
"tester2.deere.com"
],
"paths": [
"/home/test"
],
}
when you use json.dumps() it tries to use a python dictionary and dumps it as a JSON object, or when you have a json string object, you can use json.loads() to load it as a python dictionary, in this如果您只需要打印 response_API.json()
data = (response_API.json())
print(data["digest"]
結果必須是:
“1234121234”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.