python3操作json

import json
class OperationJson:
    def __init__(self):
        self.data=self.read_data()
    #读取json文件
    def read_data(self):
        with open("../dataconfig/login.json",encoding="utf-8") as fp: #添加encoding 防止出乱码
            data = json.load(fp) 
            return data
     #根据关键字获取
    def get_data(self,id):
        return self.data[id]
if __name__ == '__main__':
    opjson = OperationJson()
    print(opjson.get_data("login"))

  

posted @ 2018-10-12 15:26  studylady  阅读(256)  评论(0编辑  收藏  举报