simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

提示说是解码错误

 

可以用下面的方法判断json文件是否为空

import json
#读取 with open(
'tmp.json', 'r') as f: data = f.read() if(not bool(data)): print("json is empty!")

 但是在非空情况下会报错!!!

import json
data ={"vf":"ff"}
#写入 with open(
'tmp.json', 'w') as f: json.dump(data, f) #读取 with open('tmp.json', 'r') as f: data = f.read() print(data)
#判断
if(not bool(data)): print("json is empty!")

 已解决!!!https://www.cnblogs.com/sea-stream/p/10011699.html

相关文章:

  • 2021-09-04
  • 2021-09-05
  • 2022-12-23
  • 2021-05-20
  • 2022-01-13
  • 2021-12-09
  • 2022-01-05
猜你喜欢
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
相关资源
相似解决方案