python - json: TypeError: '<li>...spam...</li>' is not JSON serializable -


within following class trying save state information json file, when attempt save dictionary come across typeerror: '<li>...stuff...</li>' not json serializable

class save(object):     def __init__(self, mainframedict):         super(save, self).__init__()         self.mainframedict = mainframedict         import pdb; pdb.set_trace()         self.writejson()     def writejson(self):         self.json_state_file = os.path.join(self.mainframedict['item_folder'],                                             self.mainframedict['itemnumber']+'.json')         open(self.json_state_file,'wb') f:             json.dump(self.mainframedict['currentiteminfo'], f)         self.printjsonstatefile()         #import pdb; pdb.set_trace()     def printjsonstatefile(self):         open(self.json_state_file,'rb') f:             json_data = json.loads(f) 

within dictionary trying save:

(pdb) print(self.mainframedict['currentiteminfo'].keys()) ['image_list', 'description', 'specs'] (pdb) print(self.mainframedict['currentiteminfo']['description']) run time in comfort of own home. deluxe treadmill features 9 programs; plug in mp3 player rock workout! <ul> <li>horizon t101 deluxe treadmill</li> <li>55" x 20" treadbelt</li> <li>9 programs</li> <li>fan</li> <li>motorized incline 10%</li> <li>up 10 mph</li> <li>surround speakers compatible mp3 player (not included)</li> <li>71"l x 33"w x 55"h</li> <li>wheels mobility</li> <li>folds storage</li> <li>weight limit: 300 lbs.</li> <li>assembly required</li> <li>limited warranty</li> <li>made in usa</li> </ul> (pdb) print type(self.mainframedict['currentiteminfo']['description']) <class 'bs4.beautifulsoup'> 

the traceback trying figure out:

traceback (most recent call last):   file "display_image.py", line 242, in onnewitembutton save(mainframe.__dict__)   file "display_image.py", line 20, in __init__ self.writejson()   file "display_image.py", line 24, in writejson json.dump(self.mainframedict['currentiteminfo'], f)   file "c:\python27\lib\json\__init__.py", line 189, in dump chunk in iterable:   file "c:\python27\lib\json\encoder.py", line 434, in _iterencode chunk in _iterencode_dict(o, _current_indent_level):   file "c:\python27\lib\json\encoder.py", line 408, in _iterencode_dict chunk in chunks:   file "c:\python27\lib\json\encoder.py", line 442, in _iterencode o = _default(o)   file "c:\python27\lib\json\encoder.py", line 184, in default raise typeerror(repr(o) + " not json serializable") typeerror: run time in comfort of own home. deluxe treadmill features 9 programs; plug in mp3 player rock workout! <ul> <li>horizon t101 deluxe treadmill</li> <li>55" x 20" treadbelt</li> <li>9 programs</li> <li>fan</li> <li>motorized incline 10%</li> <li>up 10 mph</li> <li>surround speakers compatible mp3 player (not included)</li> <li>71"l x 33"w x 55"h</li> <li>wheels mobility</li> <li>folds storage</li> <li>weight limit: 300 lbs.</li> <li>assembly required</li> <li>limited warranty</li> <li>made in usa</li> </ul>  not json serializable 

docs/posts looked at:

i not sure if because nested, or if there issue encoding/decoding. looking , not understanding? there way determine encoding of item?

what type of self.mainframedict['currentiteminfo']['description']?

it's not str, int, float, list, tuple, bool or none, json doesn't know it. you'll need convert 1 of types...


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -