python3.6 复杂string转成dict

'{"id": 111,"texts": [{}], "is_tokenized": false}'.format("query")
有个字符串如上所示,想把以上的字符串转成dict,考虑到可以使用eval或者ast.literal_eval,但是尝试了好多种方法,始终没有成功,求助大神

字符串使用format格式化的时候,如果字符串中有{或者}占位符,需要写两个,query字符串需要""包裹;

import json
a = '{{"id": 111,"texts": [{}], "is_tokenized": false}}'.format('"query"')
print(json.loads(a))

如果用ast,需要把false替换成False

import ast
a = '{{"id": 111,"texts": [{}], "is_tokenized": false}}'.replace('false', 'False').format('"query"')
print(ast.literal_eval(a))

Created on Oct 14, 2014

@author: Jay smile665@gmail.com
'''

import MySQLdb
import ast
import json

def my_run():
try:
s = '{"host":"192.168.11.22", "port":3306, "user":"abc",\
"passwd":"123", "db":"mydb", "connect_timeout":10}'
d = ast.literal_eval(s)
print type(d)
print d
d1 = eval(s)
print type(d1)
print d1
d2 = json.loads(s)
print type(d2)
print d2
MySQLdb.Connect(host=d['host'], port=d['port'], user=d['user'],
passwd=d['passwd'], db=d['db'],
connect_timeout=d['connect_timeout'])
print 'right'
except Exception, e:
print 'wrong %s' % e

if name == '__main__':
my_run()

https://www.cnblogs.com/sunshine2016/p/6197836.html