python response.text返回值为{"returnStatus": "1 ", "message": "成功", "remainPoint": "241", "taskId": "3313746", "successCounts": "1"}如何获取其中关键字的值
时间: 2024-03-10 19:42:42 浏览: 129
要获取其中关键字的值,你可以使用Python中的json库来解析返回的JSON字符串。首先,你需要将返回的字符串转换为JSON对象,然后通过键来获取对应的值。
以下是一个示例代码:
```python
import json
response_text = '{"returnStatus": "1 ", "message": "成功", "remainPoint": "241", "taskId": "3313746", "successCounts": "1"}'
response_json = json.loads(response_text)
return_status = response_json["returnStatus"]
message = response_json["message"]
remain_point = response_json["remainPoint"]
task_id = response_json["taskId"]
success_counts = response_json["successCounts"]
print("returnStatus:", return_status)
print("message:", message)
print("remainPoint:", remain_point)
print("taskId:", task_id)
print("successCounts:", success_counts)
```
输出结果:
```
returnStatus: 1
message: 成功
remainPoint: 241
taskId: 3313746
successCounts: 1
```
阅读全文