![](/img/trans.png)
[英]json.decoder.JSONDecodeError: Expecting value: , json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes:
[英]json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes
我有以下字符串,我試圖將其轉換為 python 中的字典:
data = "{'ABC - 1 check NEW_PAGE': 'red', 'CDE - 2 checks SQL_DATA': 'black', 'The temporary file generated contains the following errors : ['20235874;172426;admin_AB_34;S_DEB;100;FC_SUCCESS_F']': 'red'}"
我在 python 中嘗試使用的是以下代碼行:
data = data.replace("'", "\"")
data = json.loads(data)
我收到以下錯誤:
json.decoder.JSONDecodeError: Expecting ':' delimiter: line 1 column 187 (char 186)
有人可以幫我解決嗎? 真的很感激
你是 escaping '
,但在"
之間時沒有必要:
data = data.replace("'", "\"")
data = json.loads(data)
但是您可能會遇到數據字符串末尾的另一個問題"'The temporary file generated contains the following errors: ['20235874;172426;admin_AB_34;S_DEB;100;FC_SUCCESS_F']'; 'red'"
。 這似乎是無效的 json 字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.