【Json抽取】gpt,qwen,chatglm等大模型输出json后如何处理

很多人不知道如何去抽取 json 格式的数据,其实很简单, 找到 开始和 结束的 两个 括号,然后解析这个字符串就可以了。代码如下

python 复制代码
import json
def parser_simple_json(text):
    # find the { index
    start = text.find("{")
    # find the } index
    end = text.find("}")
    # extract the json string
    json_string = text[start:end+1]
    # parse the json string
    data = json.loads(json_string)
    return data
相关推荐
卓怡学长13 分钟前
m111基于MVC的舞蹈网站的设计与实现
java·前端·数据库·spring boot·spring·mvc
写代码的【黑咖啡】13 分钟前
Python中的JSON处理(标准库)
开发语言·python·json
存在的五月雨18 分钟前
Redis的一些使用
java·数据库·redis
Elias不吃糖8 小时前
Java Lambda 表达式
java·开发语言·学习
情缘晓梦.8 小时前
C语言指针进阶
java·开发语言·算法
南知意-9 小时前
IDEA 2025.3 版本安装指南(完整图文教程)
java·intellij-idea·开发工具·idea安装
wtsolutions10 小时前
JSON to Excel Add-in - Seamless Integration Within Excel
json·excel
码农水水10 小时前
蚂蚁Java面试被问:混沌工程在分布式系统中的应用
java·linux·开发语言·面试·职场和发展·php
wtsolutions10 小时前
Getting Started with JSON to Excel Web App - Convert in Seconds
json·excel·web app
海边的Kurisu10 小时前
苍穹外卖日记 | Day4 套餐模块
java·苍穹外卖