开发者

python - simplejson not serializing

开发者 https://www.devze.com 2023-01-24 01:46 出处:网络
when i try to serialize the list variable returned by the database query, an error of \'non-serializable is returned.But when i hardcode the same exact string in, or so it seems...serialization works.

when i try to serialize the list variable returned by the database query, an error of 'non-serializable is returned. But when i hardcode the same exact string in, or so it seems...serialization works. Any ideas why?

car_list = Car.objects.get(id=query).all_cars.values('id','name').order_by('name')
#car_list = [{'id': 9L, 'name': u"Porche"}, {'id': 6L, 'name': u'Toyota'}, {'id': 7L, 'name': u'Hugo'}, {'id': 3L, 'name': u'Honda'}]
data = { 'list':car_list }
print simpl开发者_如何转开发ejson.dumps(data)


simplejson cannot serialize Django types. Pass the result to list() to turn it into something simplejson can serialize.

0

精彩评论

暂无评论...
验证码 换一张
取 消