在 Python 中将字符串转换为 json [关闭]

问题描述 投票:0回答:1

我正在尝试使用 json.loads 将以下字符串转换为 json 对象。

"Error":"Execution failed on sql 'SELECT * FROM tablename': ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Query timeout expired (0) (SQLExecDirectW)')"

我收到以下错误。

JSONDecodeError: Extra data: line 1 column 8 (char 7)

我们如何将上面的字符串转换成json对象

TIA.

python json
1个回答
1
投票

将大括号括起来以获得对象的有效 JSON 语法。

result = json.loads('{' + bad_json + '}')
© www.soinside.com 2019 - 2024. All rights reserved.