#coding:utf-8
import requests,json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
par={'type':'yunda','postid':'3901357983152'}
# data_json=json.dumps(par)
r=requests.get('https://www.kuaidi100.com/query',params=par,verify=False)
content=r.json()
print type(content)
def format_json(content):
try:
result = json.dumps(content, sort_keys=True, indent=4, separators=(',', ': ')). \
encode('latin-1').decode('unicode_escape')
except:
result = json.dumps(content, sort_keys=True, indent=4, separators=(',', ': ')). \
decode("unicode_escape")
return result
print format_json(content)
其实就是这一句起作用
json.dumps(text, sort_keys=True, indent=4, separators=(',', ': '))
网友评论