我試圖解碼一些JSON使用Python 3. json
庫時引起「期望值......」錯誤:datetime.datetimes在JSON是導致「期待值」的錯誤在Python
>>> import json
>>> json.loads("datetime.datetime(2017, 1, 1, 0, 0, 0, 0)")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Jack\AppData\Local\Programs\Python\Python35\lib\json\__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "C:\Users\Jack\AppData\Local\Programs\Python\Python35\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Jack\AppData\Local\Programs\Python\Python35\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
使用object_hook在這裏似乎沒有幫助,我嘗試添加一個,但它甚至沒有被調用。這是怎麼回事?
是什麼讓你認爲這是有效的JSON? –
你究竟想在這裏做什麼?正如Martijn所說 - 這不是JSON - 但我想知道你是否試圖創建一個例子在這裏發佈,也許簡化它有點誤導你可能實際上試圖實現... –
@MartijnPieters它出現在我從API獲得的一些JSON中。我一開始也很驚訝,但後來我發現了很多類似的使用datetime和JSON的python問題,我認爲這只是我沒有意識到的一些JSON特性。 –