Python之json()使用

json()

  • 功能:将是JSON格式的字符串转化为字典
  • 例子:
import requests
response = requests.get("http://httpbin.org/get")

print(response.text)
print(type(response.text))

print(response.json())
print(type(response.json()))
#运行结果
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Host": "httpbin.org",
    "User-Agent": "python-requests/2.21.0"
  },
  "origin": "117.81.168.216, 117.81.168.216",
  "url": "https://httpbin.org/get"
}
<class 'str'>
{'args': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.21.0'}, 'origin': '117.81.168.216, 117.81.168.216', 'url': 'https://httpbin.org/get'}
<class 'dict'>

猜你喜欢

转载自blog.csdn.net/weixin_43411585/article/details/88854875
今日推荐