I was trying to serialize a Python list but got errors that it's not serializable. Is there a limitation on serializing a list of Long integers?
>>> ids=p.values_list('id',flat=True)
>>> ids
[335L, 468L, 481L, 542L, 559L, 567L, 609L]
>>> import simplejson as json
>>> str=json.dumps(ids)
Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\Google\google_appengine\lib\simplejson\simplejson\__ini
t__.py", line 265, in dumps
return _default_encoder.encode(obj)
File "C:\Program Files\Google\google_appengine\lib\simplejson\simplejson\encod
er.py", line 216, in encode
chunks = list(chunks)
File "C:\Program Files\Google\google_appengine\lib\simplejson\simplejson\encod
er.py", line 495, in _iterencode
o = _default(o)
File "C:\Program Files\Google\google_appengine\lib\simplejson\simplejson\encod
er.py", line 190, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: [335L, 468L, 481L, 542L, 559L, 567L, 609L] is not JSON serializable
>>> it works for me either with simplejson and json. btw, it is a bad idea to assign to str
以上就是serializing result of a queryset with json raises error:的详细内容,更多请关注web前端其它相关文章!