python中的json模块是一个轻量级的数据交换格式。不能简单的理解为一种像str  list   int 之类的数据格式,是用来数据交换的格式。

最近在写的一个自动化测试的脚本中有使用到 json 的相关知识,脚本中基本上将json的常用方法和使用都涉及了,所以下面基于这个脚本来学习json。

python json模块使用介绍

line 2:import json    # 导入json模块

line 6:requests.post(xxxxxx).json()   : #   json() 方法用来将前面post得到的的response 解析为JSON。

line 7:json.dumps() 方法将dict 格式转换成str 格式。

res=json.dumps(result, ensure_ascii=False, sort_keys=True,indent=2)

result : dumps要处理的数据;

ensure_ascii = False :为false时,即使result 中含有汉字也可以正常显示;

python json模块使用介绍

indent=2:表示数据的缩进;

python json模块使用介绍

sort_keys = True : 

python json模块使用介绍

 

相关文章:

  • 2021-11-02
  • 2019-11-23
  • 2019-03-11
  • 2021-09-28
  • 2021-10-19
  • 2021-11-03
  • 2021-10-19
  • 2021-09-14
猜你喜欢
  • 2020-03-15
  • 2020-03-15
  • 2021-01-25
  • 2021-10-21
  • 2021-12-16
  • 2019-10-10
  • 2020-01-25
  • 2019-11-15
相关资源
相似解决方案