Spaces:
Sleeping
Sleeping
Mise à jour du parsing json
Browse files
app.py
CHANGED
|
@@ -71,10 +71,10 @@ def extract_json_from_response(response):
|
|
| 71 |
Retourne un objet Python (dict) ou None si extraction impossible.
|
| 72 |
"""
|
| 73 |
|
| 74 |
-
# Recherche
|
| 75 |
-
|
| 76 |
-
if
|
| 77 |
-
json_str =
|
| 78 |
try:
|
| 79 |
return json.loads(json_str)
|
| 80 |
except Exception as e:
|
|
|
|
| 71 |
Retourne un objet Python (dict) ou None si extraction impossible.
|
| 72 |
"""
|
| 73 |
|
| 74 |
+
# Recherche tous les objets JSON et prend le premier (le plus probable d'être le bon)
|
| 75 |
+
matches = re.findall(r'({.*?})', response, re.DOTALL)
|
| 76 |
+
if matches:
|
| 77 |
+
json_str = matches[0]
|
| 78 |
try:
|
| 79 |
return json.loads(json_str)
|
| 80 |
except Exception as e:
|