Wie man eine Klasse JSON serialisierbar macht

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie man eine Klasse JSON serialisierbar macht

by Anonymous » 21 Aug 2025, 09:10

Wie kann man eine serialisierbare Python -Klasse machen? < /p>

Code: Select all

class FileItem:
def __init__(self, fname):
self.fname = fname
< /code>
Versuch, mit JSON zu serialisieren: < /p>
>>> import json
>>> x = FileItem('/foo/bar')
>>> json.dumps(x)
TypeError: Object of type 'FileItem' is not JSON serializable

Top