2012-07-23 50 views

回答

1
class Handler(webapp2.RequestHandler): 
    def get(self): 
     <do your GQLQuery here> 
     self.response.headers['Content-Type'] = 'application/json' 
     self.response.body = json.dumps(<your data in dict or dict list>) 
     self.response.set_status(200) 
5

您可以將您的數據存儲模型轉換到一個字典,然後使用simplejson(蟒蛇2.5)或JSON(Python 2.7版)軟件包的字典轉換成JSON。通常,這是你的處理器的最後一行是如何將看起來像:

self.response.out.write(simplejson.dumps(some_datastore_entity.to_dict())) 

新的NDB接口,數據存儲提供了默認情況下to_dict方法。你可以看看here

+0

不僅ndb接口有一個to_dict:https://developers.google.com/appengine/docs/python/datastore/functions#to_dict – voscausa 2012-07-23 09:08:03

相關問題