好吧,根据您的问题(不太清楚),但据我了解,您需要在线用户的“价格”列表,而“价格”在您的 json 数据中表示铂金价值。所以要这样做。
试试这个:
import json
filedata = open('jsondata.txt', 'r')
jsondata = json.load(filedata)
ingame_users_platinum = []
offline_users_platinum = []
for i in jsondata['payload']['orders']:
if i['user']['status'] == 'offline':
offline_users_platinum.append(i['platinum'])
elif i['user']['status'] == 'ingame':
ingame_users_platinum.append(i['platinum'])
print("Price/Platinum of ingame users: \n", ingame_users_platinum)
print("Price/Platinum of offline users: \n", offline_users_platinum)
这将为您提供如下输出:
Price/Platinum of ingame users:
[35000, 70000, 2000, 69, 10, 75000, 500, 1000, 100, 500]
Price/Platinum of offline users:
[30000, 28282, 10000, 3200, 1, 2000, 25, 666, 55000, 10000, 2000, 30, 25000, 4200, 10, 20000, 100, 1000, 45000, 20000, 1000, 4500, 300, 20000, 20000, 20000, 50000, 66666, 6666, 200, 200, 5000, 50000, 11000, 8, 100, 500, 50, 4500, 66000, 69000, 5, 20, 150, 400, 42, 5, 20000, 25000, 36000, 69, 10, 1000, 1, 450, 1, 40000, 1000, 120, 68000, 100, 1, 20000, 322, 1, 1, 60000, 50000, 53000, 5, 5000, 1, 1000, 1, 1, 100, 8000, 10000, 40000, 5000, 100, 1, 1, 200, 20, 1, 500, 46, 500, 1, 40000, 20, 133337, 911, 188888, 10000, 1, 1, 1, 1, 1, 30000, 200, 40000, 100000, 90000, 199999, 1, 10, 1, 150]
按顺序对这些列表进行排序:
这样做:
ingame_users_platinum.sort(key=int, reverse=True) # For sorted in desc
offline_users_platinum.sort(key=int, reverse=True) # For sorted in desc
然后再次打印它们以获得输出。 像这样:
Price/Platinum of ingame users:
[75000, 70000, 35000, 2000, 1000, 500, 500, 100, 69, 10]
Price/Platinum of offline users:
[199999, 188888, 133337, 100000, 90000, 69000, 68000, 66666, 66000, 60000, 55000, 53000, 50000, 50000, 50000, 45000, 40000, 40000, 40000, 40000, 36000, 30000, 30000, 28282, 25000, 25000, 20000, 20000, 20000, 20000, 20000, 20000, 20000, 11000, 10000, 10000, 10000, 10000, 8000, 6666, 5000, 5000, 5000, 4500, 4500, 4200, 3200, 2000, 2000, 1000, 1000, 1000, 1000, 1000, 911, 666, 500, 500, 500, 450, 400, 322, 300, 200, 200, 200, 200, 150, 150, 120, 100, 100, 100, 100, 100, 69, 50, 46, 42, 30, 25, 20, 20, 20, 10, 10, 10, 8, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
希望对您有所帮助! :)