Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

python 3.x - How would I be able to compare 2 sets of JSON data and check if one is in the other

So I am coding a Discord bot using Python that gets the data from Roblox's API to check if a user is in a allied group. So I made a loop to find if the user is in the same group but it does not work as intended. When I was testing it, it would say I was not in the group even though I was. I received no errors when running this code:

for x in data:
                num = data.index(x)
                if data[num]["Name"] == "ΒΕ ? British Empire":
                    print("its bigs squad")
                    print(data[num]["Role"])
                    bruh = str(data[num]["Role"])




                    dat = requests.get("https://api.roblox.com/groups/8616457/allies")
                    date = dat.json()['Groups']
                    groups = list(date)

                    for f in groups:
                        e = groups.index(f)
                        print(e)
                        if data[num]['Name'] == groups[e]['Name']:
                            print("in group")
                            member = ctx.author
                            role = discord.utils.get(member.guild.roles, name=bruh)
                            await member.add_roles(role)
                            await ctx.send(f"Gave the **{bruh}** role!") #fix
                        else:
                            print("not in group")```

###JSON data I am comparing


{"Groups":[{"Name":"ΒΕ ? Administration","Id":8664914,"Owner":{"Name":"EA6Y","Id":100403322},"EmblemUrl":"http://www.roblox.com/asset/?id=6109292568","Description":"?????????????????????? & ????????????????????????????
???????????

The Development & Administration team include developers, administrators, and moderators that keep the group running smoothly, in-game, and in the communication servers."```

###Also comparing this one


[{"Name":"Roblox","Id":7,"EmblemUrl":"http://www.roblox.com/asset/?id=607941191","EmblemId":607941191,"Rank":255,"Role":"Owner","IsPrimary":false,"IsInClan":false},{"Name":"Roblox Wiki","Id":127081,"EmblemUrl":"http://www.roblox.com/asset/?id=607954721","EmblemId":607954721,"Rank":254,"Role":"Wiki System Operator","IsPrimary":false,"IsInClan":false}]
question from:https://stackoverflow.com/questions/65863318/how-would-i-be-able-to-compare-2-sets-of-json-data-and-check-if-one-is-in-the-ot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...