【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
相关推荐
rabbit_pro1 天前
Java使用Mybatis-Plus封装动态数据源工具类
java·python·mybatis
期待のcode1 天前
Java虚拟机类加载机制
java·开发语言
短剑重铸之日1 天前
《SpringBoot4.0初识》第四篇:原生镜像
java·原生镜像·springboot4.0
程序员欣宸1 天前
LangChain4j实战之十二:结构化输出之三,json模式
java·人工智能·ai·json·langchain4j
天若有情6731 天前
打破思维定式!C++参数设计新范式:让结构体替代传统参数列表
java·开发语言·c++
亲爱的非洲野猪1 天前
从ReentrantLock到AQS:深入解析Java并发锁的实现哲学
java·开发语言
wheelmouse77881 天前
如何设置VSCode打开文件Tab页签换行
java·python
yangminlei1 天前
Spring Boot——日志介绍和配置
java·spring boot
廋到被风吹走1 天前
【Spring】Spring Boot Starter设计:公司级监控SDK实战指南
java·spring boot·spring
码头整点薯条1 天前
启动报错:Invalid value type for attribute ‘factoryBeanObjectType‘ 解决方案
java