I am using dict to create a json object but I am having some issue with dict and json!
def get(self):
players = db.GqlQuery("SELECT * FROM Player")
playerInfo = {}
for player in players:
email = player.email.encode("utf-8")
gem = str(player.gem)
print email
print gem
playerInfo["email"] = email
playerInfo["gem"] = gem
b = json.dumps(playerInfo)
self.response.out.write(b)
For some reason I only received one and the for loop, and when I print email in the for loop I received 6 results but the output of playerInfo only has 1 set of data.
{"email": "test1", "gem": "0"}
My expected result should be
{"email": "test1", "gem": "0"},{"email": "test2", "gem": "2"}...
What you want, I think is a list of dictionaries. That will enable you to store multiple entities:
Also, you really want to avoid using
printin you AppEngine applications. Use logging instead, asprintcan have unintended side-effects.