我正在尝试使用json库加载类似json的字符串:
data = json.loads(raw_json.replace(" ","").replace("\n",""))
但是我收到以下错误:
JSONDecodeError: Expecting ',' delimiter
我看了这个question,但它似乎没有帮助......我也不知道如何使用变量名称将我的字符串转换为原始字符串...我唯一的问题是在我的raw_json变量中可以看到它有很多空格和换行符。我的raw_json变量如下所示:
{
"search": {
"levier": "Recherchedepuislaliste",
"nbresults": "137 314",
"nbpage": "1",
"typedetransaction": ["vente", "viager"],
"nbpieces": [""],
"typedebien": ["Appartement", "Maison/Villa"],
"pays": "FR",
"nbchambres": [""],
"budget": {"min": "", "max": ""},
"surface": {"min": "", "max": ""},
"surface_terrain": {"min": "", "max": ""},
"type": [{"name": "Nouvellerecherche", "value": true},
{"name": "Dernièrerecherche", "value": false},
{"name": "Rechercheenregistrée", "value": false}],
"etage": {"min": "", "max": ""},
"tri": {"criteria": "Sélection",
"direction": ""},
"chauffage": [{"name": "individuel", "value": false},
{"name": "central", "value": false},
{"name": "electrique", "value": false},
{"name": "gaz", "value": false}]
}
答案 0 :(得分:1)
除了缺少结束括号之外,还有一切正确,只需在JSON对象的末尾添加}
。