在python使用过程中,输入中文,不能正常的输出,可以使用ensure_ascii参数来解决不能输入中文的问题

 

代码块:

import json

friends={"name":"王虎","name1":"张二","name2":"姚晨"}
print(json.dumps(friends))

执行结果:

python  json.dumps()函数输出json格式,使用ensure_ascii参数对中文输入的支持

输出的中文是中文的ascii 字符码,而不是真正的中文。
这是因为json.dumps 序列化时对中文默认使用的ascii编码
因此需要使用ensure_ascii=False来指定出中文
 
代码块: 

friends={"name":"王虎","name1":"张二","name2":"姚晨"}
print(json.dumps(friends,ensure_ascii=False)) 

 
执行结果:
python  json.dumps()函数输出json格式,使用ensure_ascii参数对中文输入的支持

 

 

 

相关文章:

  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
猜你喜欢
  • 2022-12-23
  • 1970-01-01
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
相关资源
相似解决方案