json源数据如下:{"name":"中国","province":[{"name":"多测师","citys":{"city":["上海多测师","上海多测师"]}},{"name":"多测师","citys":{"city":["上海多测师","深圳多测师","广州多测师"]}},{"name":"多测师","citys":{"city":["上海多测师","深圳多测师"]}},{"name":"多测师","citys":{"city":["上海多测师"]}}]}
#coding=utf-8"""===========================Author:多测师_王sirTime:/6/22 15:04Wechat:15367499889Company:上海多测师信息有限公司==========================="""import osclass Json_Utils:def __init__(self,path):self.path = pathdef read_json(self):file = open(self.path,'r')all = file.readlines()for j in all:print j.strip('\n') #读取json中的文件内容num = 0for i in all:num+=1print 'json文件的行数为{0}行'.format(num)if __name__ == '__main__':read = Json_Utils(r'D:\project\dcs2\api_auto\x0x0.json')read.read_json()
运行结果如下:{"name":"中国","province":[{"name":"多测师","citys":{"city":["上海多测师","上海多测师"]}},{"name":"多测师","citys":{"city":["上海多测师","深圳多测师","广州多测师"]}},{"name":"多测师","citys":{"city":["上海多测师","深圳多测师"]}},{"name":"多测师","citys":{"city":["上海多测师"]}}]}json文件的行数为29行