(src: str)
| 185 | |
| 186 | # ------------ 多对象提取(改进版) ------------ |
| 187 | def _extract_json_objects(src: str) -> List[Any]: |
| 188 | dec = JSONDecoder() |
| 189 | idx, n = 0, len(src) |
| 190 | objs: List[Any] = [] |
| 191 | |
| 192 | while idx < n: |
| 193 | m = re.search(r'[{\[]', src[idx:]) |
| 194 | if not m: |
| 195 | break |
| 196 | idx += m.start() |
| 197 | try: |
| 198 | obj, end = dec.raw_decode(src, idx) |
| 199 | # ========== 严格性检查 ========== |
| 200 | tail = src[end:].lstrip() |
| 201 | # 允许结束、逗号、换行、右括号、右中括号 |
| 202 | if tail and tail[0] not in ',]}>\n\r': |
| 203 | idx += 1 # 可能是误判,如 {"a":1 <-- 缺 } |
| 204 | continue |
| 205 | objs.append(obj) |
| 206 | idx = end |
| 207 | except JSONDecodeError: |
| 208 | idx += 1 |
| 209 | return objs |
| 210 | |
| 211 | |
| 212 | def _maybe_merge(objs: List[Any], merge_dicts: bool) -> Union[Any, List[Any]]: |
no test coverage detected