我有像
这样的数据sql = "select value, type from table"
cur.execute(sql)
row_headers = [x[0] for x in cur.description] #this will extract row headers
rv = cur.fetchall()
json_result = []
for result in rv:
json_result.append(dict(zip(row_headers, result)))
finalresult = json.dumps(json_result)
#[{'value':30,'type':'SS'},{'value':40,'type':'KK'},{'value':80,'type':'SK'}]
attrList = list(map(lambda x: x['value'], finalresult))
return attrList
我想要OP:
[30,40,80]
但我收到了错误:
attrList = list(map(lambda x: x['value'], finalresult))
TypeError: string indices must be integers
我在哪里做错了?