#exp9-4.py #database:school.json inside your pc #there are 3 solutions to get the data: #(1) pandas => df(data frame) #(2) (internet file): urllib.request + json => dict #(3) (local file) : open('filename','rt',encoding='utf-8-sig') #there are 2 structures for the data #(1)df = data frame #(2)dict #(1). pratice 3rd solution: open + json => dict # open does not need import file = open('school.json','rt',encoding='utf-8-sig') #note: not utf8-sig txt = file.read() print('all data=', txt) print() #output the 1st school data import json #transfer json into dict d1 = json.loads(txt) print('1st school name,address=',d1[0]['name'],d1[0]['address'] ) print() #output all school name,address for item in d1: print(item['name'],item['address']) #(2).pratice 2nd solution: pandas import pandas as pd df = pd.read_json('school.json',encoding='utf-8-sig') #output the 1st school data print() print('1st school data=',df['name'][0],df['address'][0]) #note: the dataframe index is opposite to dict #dataframe: df['name'][0] #dict : d1[0]['name'] #output all data print() print('output all data=',df)