+ 12
Trouble editing json data with python.
so, in this code ↓ https://code.sololearn.com/cy12fVMb0A2a/#py i keep getting this error when ever i try to load the data from the json file (included in the comments off the code). i haven't been able to replicate the error on here. what i'm really trying to do is figure out why it happens, and how to prevent it. the error is also in the code comments.
11 Antworten
+ 6
You have a typo in loads() too and no need to convert to str
These two line changes and it works
y = json.loads(x)
print(y)
https://code.sololearn.com/cx38vd1t09Xp/?ref=app
+ 9
Tibor Santa what's the difference between the load and the loads function?
+ 7
Hm I was kinda cheating because I followed w3s tutorial, I am by no means an expert in this.
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_json.asp
But looking up the standard doc, actually it seems correct to use load() with files and loads() with strings as data source. Well on SL it will only work with string.
+ 4
So maybe the source of the error is wrong Syntax in the source file. I am not really sure how sensitive this thing is to Whitespaces and line breaks, maybe there must be some in specific position...
+ 4
Tibor Santa, I tried your code and it worked. thanks for your help.
+ 3
Marcos Rocha then I get a TypeError
+ 2
Your script writes crap in your json while because of the truncate function.
And it throws the error when it tries to read it.
It works at the first time before the write function is executed.
+ 2
hello made some changes here is the fix.
https://code.sololearn.com/c6aEoQRAZwwo/#py
0
try using
json.loads(x)
- 1
13764557060
- 1
Mohamed