How to JSON encode Entities?

前端 未结 4 1116
我寻月下人不归
我寻月下人不归 2021-01-16 18:26

I\'m getting started with Google App Engine. I want to make AJAX chat like Twitter.

class ChatMessage(db.Model):
  message = db.StringProperty()
  created =          


        
相关标签:
4条回答
  • 2021-01-16 18:51

    I use gson for GAE/J. You can give it an object (or in your case, extract stuff from a result-set) and get a JSON string.

    0 讨论(0)
  • 2021-01-16 18:52

    Check the error log for the app engine. It will tell you what error it is experiencing. Probably you are trying to encode a Python type that json it not familiar with. JSON will only do simple stuff like lists and dictionaries. You can't use it for complex, custom types.

    0 讨论(0)
  • 2021-01-16 19:05

    In App Engine Python you can use this script to encode db.Models to JSON. You may have to customize some parts, like the DateTime formatting.

    http://code.google.com/p/google-app-engine-samples/source/browse/trunk/geochat/json.py?r=55

    0 讨论(0)
  • 2021-01-16 19:08

    You can't use simplejson.dumps() on a list of db.Model items directly.

    See my answer for extending db.Model with some handy methods for serialising db.Model instances

    0 讨论(0)
提交回复
热议问题