提取包含 lat/lon/city/country 的 JSON 对象
(text)
| 30 | return objects |
| 31 | |
| 32 | def find_coords_json(text): |
| 33 | """ |
| 34 | 提取包含 lat/lon/city/country 的 JSON 对象 |
| 35 | """ |
| 36 | json_candidates = extract_all_json_objects(text) |
| 37 | |
| 38 | for cand in json_candidates: |
| 39 | try: |
| 40 | obj = json.loads(cand) |
| 41 | except json.JSONDecodeError: |
| 42 | continue |
| 43 | |
| 44 | if all(k in obj for k in ("lat", "lon", "city", "country")): |
| 45 | return obj |
| 46 | return None |
| 47 | |
| 48 | def extract_solution(solution_str): |
| 49 | result = find_coords_json(solution_str) |
no test coverage detected