对不起伙计们,我找不到令人满意的答案来打印部分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 = json.loads(json_data) data_set = (data['data']) print(data_set)
但我得到的错误:TypeError:JSON对象必须是str,而不是’dict’