json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

前端 未结 2 1227
Happy的楠姐
Happy的楠姐 2021-02-03 23:36

I am trying to import a file which was saved using json.dumps and contains tweet coordinates:

{
    \"type\": \"Point\", 
    \"coordinates\": [
            


        
2条回答
  •  感情败类
    2021-02-04 00:06

    json.loads() takes a JSON encoded string, not a filename. You want to use json.load() (no s) instead and pass in an open file object:

    with open('/Users/JoshuaHawley/clean1.txt') as jsonfile:
        data = json.load(jsonfile)
    

    The open() command produces a file object that json.load() can then read from, to produce the decoded Python object for you. The with statement ensures that the file is closed again when done.

    The alternative is to read the data yourself and then pass it into json.loads().

提交回复
热议问题