class OperationJson: def __init__(self): self.excel = OperationExcel() def getReadJson(self): with open(data_dir(fileName='requestData.json'), encoding='utf-8') as fp: data = json.load(fp) return data def getRequestsData(self, row): '''获取请求参数''' return json.dumps( self.getReadJson()[self.excel.get_request_data(row=row)]) def getReadJson2(self): with open(data_dir(fileName='requestData2.json'), encoding='utf-8') as fp: data = json.load(fp) return data def getRequestsData2(self, row): '''获取请求参数''' return json.dumps( self.getReadJson2()[self.excel.get_request_data(row=row)])
class OperationJson: def __init__(self): self.excel = OperationExcel() #继承OperationExcel类的方法,这里是是对类的实例化处理 def getReadJson(self): # 读取json文件 # 读取过程中遇到json.decoder.JSONDecodeError,需要将json文件中的False改为"false" with open(data_dir('data', 'requestData.json'), 'r', encoding='utf-8') as f: # print(type(json.load(f))) #多了这行代码会出错,数据类型为字典 return json.load(f) def getRequestData(self, row): ''' 取请求参数 json.dumps()将字典处理为json ''' return json.dumps(self.getReadJson()[self.excel.get_request_data(row)]) # opera=OperationJson() # print(opera.getRequestData(1)) # a='\u81ea\u52a8\u5316\u6d4b\u8bd5' # print(type(a)) # print(str(a)) # print(type(a)) # print(bytes(a,encoding='gb2312')) # print(type(a))
class OperationJson: def __init__(self): self.excel=OperationExcel() def getReadJson(self): with open(data_dir(filename="requestData.json"),encoding="utf-8") as fp: data=json.load(fp) return data def getRequestsData(self,row): '''获取请求参数''' return self.getReadJson()[self.excel.get_request_data(row=row)]
class OperationJson(object): def __init__(self): self.excel = OperationExcel() def getReadJson(self): with open(data_dir(filename='requestData.json'), 'r', encoding='utf-8') as f: return json.load(f) def getRequestsData(self, row): """获取请求参数""" return json.dumps(self.getReadJson()[self.excel.get_request_data(row=row)]) # opera = OperationJson() # print(opera.getRequestsData(2))
class OperationJson: '''获取json文件中的数据''' def __init__(self): self.excel = OperationExcel() def getReadJson(self): #with open((DATA_PATH+'\\requestData.json'),encoding='utf-8') as fp: with open((DATA_PATH + '\\ots_requestData.json'), encoding='utf-8') as fp: data = json.load(fp) return data def getRequestsData(self, row): #return self.getReadJson()[self.excel.get_request_data(row=row)] return json.dumps( self.getReadJson()[self.excel.get_request_data(row=row)])
class OperationJson: def __init__(self): self.excel=OperationExcel() def getReadJson(self): '''从json文件读取数据''' with open(data_dir(fileName='requestData.json'),encoding='utf-8') as fp: #反序列化,把json字符串转换为python数据类型 data = json.load(fp) return data def getRequestsData(self,row): '''获取请求参数''' #序列化,把python数据类型转换为字典类型 pydata=json.dumps(self.getReadJson()[self.excel.get_request_data(row=row)]) return pydata