serializing result of a queryset with json raises error:

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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JSON 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏