Reading JSON from a file?

前端 未结 7 2088
無奈伤痛
無奈伤痛 2020-11-22 03:33

I am getting a bit of headache just because a simple looking, easy statement is throwing some errors in my face.

I have a json file called strings.json like this:

7条回答
  •  暖寄归人
    2020-11-22 03:49

    The problem is using with statement:

    with open('strings.json') as json_data:
        d = json.load(json_data)
        pprint(d)
    

    The file is going to be implicitly closed already. There is no need to call json_data.close() again.

提交回复
热议问题