json - Pandas 从嵌套的 json 中读取一个参数
问题描述
我有一个以下 json 文件,我想读取所有参数:仅“dataRecordId”并将它们存储到 df 中:
{'responseInformation': '20 metadata records in response.',
'metaDataResponse': [{'timestampFrom': '2020-10-07T10:19:07.7810000Z',
'timestampTo': '2020-10-07T23:59:59.9999990Z',
'component': {'type': '', 'id': '', 'name': '', 'comment': ''},
'resource': {'type': 'EQU', 'id': '6100380', 'name': '', 'comment': ''},
'processStep': {'type': '', 'id': '', 'name': '', 'comment': ''},
'context': '',
'dataRecords': [{'dataRecordId': '171533103',
'groupName': 'Process',
'sensorName': 'AutomaticProcessActive',
'profile': 'sd',
'type': 'Switch2Way',
'unit': 'state',
'returnType': 'timeSeries'}]},
{'timestampFrom': '2020-10-08T00:00:00.6540000Z',
'timestampTo': '2020-10-08T23:59:59.9999990Z',
'component': {'type': '', 'id': '', 'name': '', 'comment': ''},
'resource': {'type': 'EQU', 'id': '6100380', 'name': '', 'comment': ''},
'processStep': {'type': '', 'id': '', 'name': '', 'comment': ''},
'context': '',
'dataRecords': [{'dataRecordId': '171534669',
'groupName': 'Process',
'sensorName': 'AutomaticProcessActive',
'profile': 'sd',
'type': 'Switch2Way',
'unit': 'state',
'returnType': 'timeSeries'}]},
这是我到目前为止所做的,但我不知道如何深入结构,以实现“dataRecordId”:
import json
with open('file_200826_201026.json') as json_file:
data = json.load(json_file)
for p in data['metaDataResponse']:
print('p['dataRecords'])
解决方案
推荐阅读
- networking - 如何将默认网关添加到子网
- azure - 如何使用 azure JavaScript 函数应用在 cosmos DB 中插入数据?
- graphql - Apollo 客户端 - 子类型的缓存重定向
- reactjs - 如何在 React-Native 中实现输入文本屏蔽?
- java - 用于在 Java 中搜索日期类型的 RangeQuery
- ios - 如何防止在 Xamarin.Forms App 中的页面之间转换期间显示 iOS 通知警报?
- c++ - 从文本文件中读取并保存到列表
- r - 将 API 保存为环境变量(用于在 R 中设置 monkeylearn)
- node.js - 无法在 Lambda 函数中的模块外部使用导入语句
- java - 在 MacOS 10.15.1 (Catalina) 上安装 SOAPUI 5.5.0 的问题