Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7669201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:32:32+00:00 2026-05-31T15:32:32+00:00

I am using dict to create a json object but I am having some

  • 0

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"}...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:32:33+00:00Added an answer on May 31, 2026 at 3:32 pm

    What you want, I think is a list of dictionaries. That will enable you to store multiple entities:

    players = db.GqlQuery("SELECT * FROM Player")
    
    playerInfo  = []
    
    for player in players:
        email = player.email.encode("utf-8")
        gem =  str(player.gem)
    
        playerInfo.append({"email" :email, "gem": gem})
    
    b = json.dumps(playerInfo)
    
    self.response.out.write(b)
    

    Also, you really want to avoid using print in you AppEngine applications. Use logging instead, as print can have unintended side-effects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JSON serialization Python using simpleJSON How do I create an object so that we
I am trying to create a new dict using a list of values of
Currently I'm using var x = dict.ContainsKey(key) ? dict[key] : defaultValue I'd like some
I have a dict object. I dumped the data using this: for alldata in
I'm trying to create a generic IsEmpty extension but am having problems specifically with
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Is there a better way to implement a paging solution using dict than this?
I am trying to dynamically map JSON information into different objects. But I can't
i have a dict d1={'a':['in-gaap','inr',0,1],'b':['in-gaap','inr',0,2],'c':['in-ca','share',0,4],'n1':['','','','aaa']} d2={'d':['in-gaap','inr',0,'a+b'],'e':['in-gaap','inr',0,'y+t']} for k in d2.iterkeys(): a=re.findall('\w+',d2[k][3]) x2=dict([(x,d1.get(x,0)[3])for x in
I am trying to parse a json string straight into a managed object. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.