使用python从json提取数据

2024-09-29 06:34:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用python从json数据中提取某些信息。数据如下所示:

{
  
  "properties": {
    "detectedName": "servername1",
    
    
    "cpuCores": 60,
       },
  
      
    ]
    
  }
}

我需要能够检索csv中的所有数据。但对于started,我需要“detectedName”和“cpuCores”

我试过这个:

data['detectedName']['cpuCores'])

我发现“detectedName”未找到错误

有什么想法吗


Tags: csv数据信息jsondata错误propertiesstarted
2条回答

要获取detectedNamename = data['properties']['detectedName']

要获取cpuCorescores = data['properties']['cpuCores']

它们必须在不同的行上,并且都在properties键下

您需要这样写:data['properties']['detectedName'] 或数据['properties']['cpuCores']

相关问题 更多 >