我想从数据库中提取json,所以我这样做:
数据库中的内容json
'{“规则”:98}
def do():
c = conn.cursor()
c.execute("SELECT content_json FROM page_s WHERE URL = 'page'")
select = json.dumps(c.fetchone()) # return '{ "rules": 98 }
extract = json.loads(select)
print extract['rules']
但有错误
TypeError:list indices必须是整数,而不是str
答案 0 :(得分:0)
Problem 1
- namshi/jose 5.0.2 requires lib-openssl * -> the requested linked library openssl has the wrong version installed or is missing from your system, make sure to have the extension providing it.
- namshi/jose 5.0.1 requires lib-openssl * -> the requested linked library openssl has the wrong version installed or is missing from your system, make sure to have the extension providing it.
- namshi/jose 5.0.0 requires lib-openssl * -> the requested linked library openssl has the wrong version installed or is missing from your system, make sure to have the extension providing it.
- tymon/jwt-auth 0.5.9 requires namshi/jose 5.0.* -> satisfiable by namshi/jose[5.0.0, 5.0.1, 5.0.2].
- Installation request for tymon/jwt-auth ^0.5.9 -> satisfiable by tymon/jwt-auth[0.5.9].
返回一个元组,在你的情况下是一个单项元组。
所以我写道:
c.fetchone()
或直接来源:
print(extract[0]['rules'])