如何用以下json解析动态数字键。我可以手动操作
json_text['entities']['0']['uid']
,如何动态地迭代所有的键并获得所有的UID?
Code:
import os, json
import pandas as pd
path_to_json = '/home/sshuser/data/'
json_files = [pos_json for pos_json in os.listdir(path_to_json) if pos_json.endswith('.json')]
print(json_files)
# here I define my pandas Dataframe with the columns I want to get from the json
# we need both the json and an index number so use enumerate()
for index, js in enumerate(json_files):
with open(os.path.join(path_to_json, js)) as json_file:
json_text = json.loads(json_file.read())
uids= json_text['entities']['0']['uid']
print(seeMore)