Python ValueError: No JSON object could be decoded

前端 未结 6 569
深忆病人
深忆病人 2020-12-30 07:41

I\'m trying to read a json and get its values. I have a folder with the JSON\'s archives, and I need to open all archives and get the values from them.

This is the c

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 08:12

    I resolved this error by Converting the json file to UTF-8 with no BOM. Below is a python snippet and url for conversion

    myFile=open(cases2.json, 'r')
    myObject=myFile.read()
    u = myObject.decode('utf-8-sig')
    myObject = u.encode('utf-8')
    myFile.encoding
    myFile.close()
    myData=json.loads(myObject,'utf-8')
    

提交回复
热议问题