栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java: 获取http请求response中某个值

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java: 获取http请求response中某个值

需要做的:  获取http请求response-body 中某个值 具体思路:

(1)执行 http请求

(2)将请求响应转换成json格式,后续想获取某个值直接用json格式获取即可

        //CommonHttpReq是自己封装的http请求类,返回的是response-body
        String resoust= CommonHttpReq.postReqStr(expsaveBodystr,saveheaderurl,header);
        System.out.println(resoust);

        //将resoust转换成jsonPath 格式
        io.restassured.path.json.JsonPath jsonPath 
                            =io.restassured.path.json.JsonPath.from(resoust);

        //以下就是json提取字段的格式,超简单
        String rowsdata=jsonPath.get("rows").toString();
        String rows0data=jsonPath.get("rows[0]").toString();
        String reExpReportHeaderId=jsonPath.get("rows[0].reExpReportHeaderId").toString();
        String expReportNumber=jsonPath.get("rows[0].expReportNumber").toString();

        System.out.println(rowsdata);
        System.out.println(rows0data);
        System.out.println(reExpReportHeaderId);
        System.out.println(expReportNumber);

上面打印的结果依次是:

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/731823.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号