python 2.7 解析下列json 串中的 status ,{ "projectStatus": { "status": "OK", "conditions": [ { "status": "OK", "metricKey": "new_security_rating", "comparator": "GT", "periodIndex": 1, "errorThreshold": "1", "actualValue": "1" }, { "status": "OK", "metricKey": "new_reliability_rating", "comparator": "GT", "periodIndex": 1, "errorThreshold": "1", "actualValue": "1" }, { "status": "OK", "metricKey": "new_maintainability_rating", "comparator": "GT", "periodIndex": 1, "errorThreshold": "1", "actualValue": "1" } ], "periods": [ { "index": 1, "mode": "previous_version", "date": "2022-11-12T18:04:28+0800" } ], "ignoredConditions": false } }
时间: 2023-11-29 22:05:41 浏览: 44
可以使用 Python 2.7 中的 json 模块解析该 JSON 串,然后获取 projectStatus 字典中的 status 值。具体的代码如下:
```python
import json
json_str = '{ "projectStatus": { "status": "OK", "conditions": [ { "status": "OK", "metricKey": "new_security_rating", "comparator": "GT", "periodIndex": 1, "errorThreshold": "1", "actualValue": "1" }, { "status": "OK", "metricKey": "new_reliability_rating", "comparator": "GT", "periodIndex": 1, "errorThreshold": "1", "actualValue": "1" }, { "status": "OK", "metricKey": "new_maintainability_rating", "comparator": "GT", "periodIndex": 1, "errorThreshold": "1", "actualValue": "1" } ], "periods": [ { "index": 1, "mode": "previous_version", "date": "2022-11-12T18:04:28+0800" } ], "ignoredConditions": false } }'
json_obj = json.loads(json_str)
status = json_obj['projectStatus']['status']
print(status)
```
输出结果为:
```
OK
```
因此,该 JSON 串中的 status 值为 "OK"。
阅读全文