Python:在json文件中取相应的字段集
# coding:utf-8 import json def read_file(path): content='' with open(path, 'r', encoding='utf-8') as f: content=f.readlines() print('====') print(type(content[0])) dict_content=json.loads(content[0]) return dict_content def parse_data(dict_content): data_counts=dict_content.get('data').get('list') for item in data_counts: temp_list=[] depName=item.get('depStn') arrName=item.get('arrStn') temp_list.append(depName) temp_list.append(arrName) #print(temp_list) #print('-'.join(temp_list)) with open('8L.txt', 'a') as f: f.write('-'.join(temp_list) + '\n') if __name__=='__main__': dict_content=read_file(r'C:\Users\Administrator\Desktop\8L\93.json') parse_data(dict_content)