json解析[{"projectId":33,"projectName":"test告警","owner":"xietianyou","processId":8657,"processDefinitionCode":9714443682144,"processName":"test预警-1-20230529102559554","taskCode":9714435038048,"taskName":"test","taskType":"SHELL","taskState":"FAILURE","taskStartTime":"2023-05-29 10:25:34","taskEndTime":"2023-05-29 10:25:34","taskHost":"10.12.9.80:1234","logPath":"/data/dolphinscheduler/logs/9714443682144_1/8657/60360.log"}]
时间: 2023-06-29 19:19:40 浏览: 157
这是一个包含一个字典的列表,字典中包含了多个键值对,表示一个任务的各种信息。可以通过以下代码实现对json的解析:
```python
import json
json_str = '[{"projectId":33,"projectName":"test告警","owner":"xietianyou","processId":8657,"processDefinitionCode":9714443682144,"processName":"test预警-1-20230529102559554","taskCode":9714435038048,"taskName":"test","taskType":"SHELL","taskState":"FAILURE","taskStartTime":"2023-05-29 10:25:34","taskEndTime":"2023-05-29 10:25:34","taskHost":"10.12.9.80:1234","logPath":"/data/dolphinscheduler/logs/9714443682144_1/8657/60360.log"}]'
data_list = json.loads(json_str)
for data in data_list:
print('projectId:', data['projectId'])
print('projectName:', data['projectName'])
print('owner:', data['owner'])
print('processId:', data['processId'])
print('processDefinitionCode:', data['processDefinitionCode'])
print('processName:', data['processName'])
print('taskCode:', data['taskCode'])
print('taskName:', data['taskName'])
print('taskType:', data['taskType'])
print('taskState:', data['taskState'])
print('taskStartTime:', data['taskStartTime'])
print('taskEndTime:', data['taskEndTime'])
print('taskHost:', data['taskHost'])
print('logPath:', data['logPath'])
```
输出结果为:
```
projectId: 33
projectName: test告警
owner: xietianyou
processId: 8657
processDefinitionCode: 9714443682144
processName: test预警-1-20230529102559554
taskCode: 9714435038048
taskName: test
taskType: SHELL
taskState: FAILURE
taskStartTime: 2023-05-29 10:25:34
taskEndTime: 2023-05-29 10:25:34
taskHost: 10.12.9.80:1234
logPath: /data/dolphinscheduler/logs/9714443682144_1/8657/60360.log
```
阅读全文