[英]extract data from json using python
我正在嘗試使用 python 從 json 數據中提取某些信息。 數據是這樣的:
{
"properties": {
"detectedName": "servername1",
"cpuCores": 60,
},
]
}
}
我需要能夠在 csv 中檢索所有這些數據。 但首先,我需要“detectedName”和“cpuCores”。
我試過這個:
data['detectedName']['cpuCores'])
我收到 'detectedName' 未找到錯誤。
有任何想法嗎?
獲取detectedName
: name = data['properties']['detectedName']
獲取cpuCores
: cores = data['properties']['cpuCores']
這些必須在不同的行上,並且都在properties
鍵下。
你需要這樣寫: data['properties']['detectedName'] 或 data['properties']['cpuCores']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.