json.dumps(data, sort_keys=True, indet=2, ensure_ascii=False)
说明:
data 需要格式的数据,比如request接口情况返回的json()数据;
sort_keys 指请求返回的json数据中key按字母数序排序;
indent 指缩进;
ensure_ascii=False 保证中文正常输出,不显示乱码;
import requests, hashlib, time, datetime, random
import json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
base_url = 'https://www.xxxxxx.com'
api_url = '/exchange/api/v1/common/symbols'
get_symbols = requests.request(method='GET', url=base_url+api_url, verify=False)
print(get_symbols)
result_request = get_symbols.json()
print(json.dumps(result_request, sort_keys=True, indent=2, ensure_ascii=False))