我有以下数据结构,我想按upload_on排序,其中最新的时间戳首先出现:
#Function that recursively extracts values out of the object into a flattened dictionary
def flatten_json(data):
flat = [] #list of flat dictionaries
def flatten(y):
out = {}
def flatten2(x, name=''):
if type(x) is dict:
for a in x:
if a == "name":
flatten2(x["value"], name + x[a] + '_')
else:
flatten2(x[a], name + a + '_')
elif type(x) is list:
for a in x:
flatten2(a, name + '_')
else:
out[name[:-1]] = x
flatten2(y)
return out
#Loop needed to flatten multiple objects
for i in range(len(data)):
flat.append(flatten(data[i]).copy())
return json_normalize(flat)
我有以下代码来检索数据并对其进行排序:
"hd2CnPPZ5FMKjpzFJNUc4xVLVUW2" : {
"media" : {
"-KJkxpnRg_2ZK4tEjGBN" : {
"uploaded_on" : 1465405365513,
"url" : "<my-firebase-storage-url>"
},
但是,我的商品没有正确订购,最旧的时间戳首先出现。我尝试了在uploaded_on的前面放一个减号,但这没有任何区别。
我做错了什么指针?