1、json.dumps()

         json.dumps()用于将dict类型的数据转成str,因为如果直接将dict类型的数据写入json文件中会发生报错,因此在将数据写入时需要用到该函数。

 

转换案例:

 1 import json
 2  
 3 name_emb = {'a':'1111','b':'2222','c':'3333','d':'4444'} 
 4 
 5 jsObj = json.dumps(name_emb)    
 6 
 7 print(name_emb)
 8 print(jsObj)
 9 
10 print(type(name_emb))
11 print(type(jsObj))
json.dumps()用于将dict类型的数据转成str

相关文章:

  • 2022-12-23
  • 2021-08-30
  • 2021-08-21
  • 2022-02-18
猜你喜欢
  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案