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