抱歉,大家,我找不到满意的答案来打印 JSON 响应的一部分。有人可以在这里帮助我吗?
import json
import requests
import pprint
response = requests.get('<api endpoing>')
json_data = response.json()
print(json.dumps(json_data, indent=4, sort_keys=True))
{"Json响应将会是"}{
"Value1": "SomeValue",
"data": {
"subval1": false,
"subval2": "0a4",
"subval3": "",
"subval4": "Click h!",
"subval5": "1002",
"subval6": "932",
"subval7": "i2",
"subval8": 250,
"subval9": 0,
"subval10": 1,
"subval11": 3,
"subval12": 1,
"subval13": "<!>",
"subval14": "",
"subval15": "Click !!",
"subval16": "",
"subval17": 300
},
"error": true,
"message": "Success",
"status": 200
}
现在,我想遍历并仅打印"data":值。 我将执行以下操作
data = json.loads(json_data)
data_set = (data['data'])
print(data_set)
但我得到的错误是:TypeError: JSON对象必须是str类型,而不是'dict'。
json_data
的类型。如果它已经是字典,则不要进行JSON解码... - Jean-François Fabre