我正在尝试将字符串加载到 python 对象中。我收到以下错误:这是错误:期望值:第 15 行第 15 列(字符 351){'allData':无}当我将 cprob 的值更改为以下代码时,没有问题: "cprob": { "T": 1, "A": 2, "C": 3 }test.txt 中的数据:[{ "V": ["Offer", "Interview", "Grades", "Admission", "Experience"], "E": [["Grades", "Interview"], ["Experience", "Interview"], ["Grades", "Admission"], ["Interview", "Offer"]], "Vdata": { "Offer": { "ord": 4, "numoutcomes": 2, "vals": ["0", "1"], "parents": ["Interview"], "children": 0, "cprob": { "['0']": [.9, .1], "['1']": [.4, .6], "['2']": [.01, .99] } } }}]代码:import jsonclass JsonData: def __init__(self, path): self.allData = None def dictload(self, path): f = open(path, 'r') ftext = f.read() print(ftext) try: self.allData = json.loads(ftext) except Exception as e: print('This is error : ', e)path = "test.txt"jsonData = JsonData(path)jsonData.dictload(path)print(vars(jsonData))
添加回答
举报
0/150
提交
取消