python,json解析字符串时ValueError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

时间:2021-03-31 17:08:49

今天写测试工具的时候,去excel取数据,用json解析字符串为字典时报错,后经调试,发现是单引号的原因,将单引号换位双引号即可

def getExcelValue_to_dic(filepath):
    lis_vs = []
    wb = xlrd.open_workbook(filepath)
    ws = wb.sheet_by_index(0)
    rows = ws.nrows
    cols = ws.ncols
    #获取首行目录
    values1 = ws.row_values(0)
    for i in range(1,rows):
        dic = {}
        lis_v = ws.row_values(i)
        for n in range(cols):
            if n ==3 and lis_v[3]:
                dic[values1[n]] = json.loads(lis_v[n])
                print dic
            elif n == 4:
                dic[values1[n]] = json.loads(lis_v[n])
            else:
                dic[values1[n]] = lis_v[n]
        lis_vs.append(dic)
    return  lis_vs
python,json解析字符串时ValueError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)