I am very fresh in Python. I would like to read JSON files in Python, but I did not get what are the problems. Please see the image.
CodePudding user response:
You have to specify a mode to the open() function. In this case I think you're trying to read the file, so your mode would be "r". Your code should be:
with open(r'path/to/read/','r') as file:
data = json.load(file)
Your code should run now.
CodePudding user response:
Your path should not contain spaces. Please modify the file path.
Generally speaking, the file path is best to be in full English with no spaces and no special characters.
CodePudding user response:
import sys
import os
import json
def JsonRead(str):
with open(str, encoding='utf-8') as f:
data = json.load(f)
return data
new_Data = JsonRead(filePath)
Then import JsonRead in project