简体   繁体   中英

How to go about storing users data in Json

I have been messing with Json a bit today and doing some trial and error but I couldn't seem to make this work:

def checkForNewBooty(chan):
    j = urllib2.urlopen('http://tmi.twitch.tv/group/user/' + chan + '/chatters')
    j_obj = json.load(j)
    viewers = j_obj['chatters']['viewers']
    moderators = j_obj['chatters']['moderators']
    for x in viewers and moderators:
        print(json.dumps('users' = {'johhny' = {'Points' = 0, 'Time Joined' = 9938}}))

Json example of what I'm trying to do:

{
  users = {
    "johhnyknoxville" 
  }
}

What is the proper way of doing this?

Python dictionaries (which are serialized using JSON) use : and not = .

Try:

json.dumps({'users': {'johhny': {'Points': 0, 'Time Joined': 9938}}})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM