【发布时间】:2020-09-14 08:09:30
【问题描述】:
如何使用以下 json 解析动态数字键。我可以手动进行json_text['entities']['0']['uid'],如何动态迭代所有键并获取所有uid
{
"entities": {
"0":{
"uid": "3769fcb3-8312-41b8-a5c9-3c24b6a9ce96"
},
"1":{
"uid": "3769fcb3-8312-41b8-a5c9-3c24b6a9ce97"
},
"2":{
"uid": "3769fcb3-8312-41b8-a5c9-3c24b6a9ce98"
}
"3":{
;
}
:
:
:
}
}
代码:
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)
【问题讨论】:
标签: python json python-3.x python-2.7