gpt4 book ai didi

java - 放心。是否可以从请求 json 中提取值?

转载 作者:IT老高 更新时间:2023-10-28 12:46:34 25 4
gpt4 key购买 nike

我收到这样的回复:

Response response = expect().statusCode(200).given().body(requestBody).contentType("application/json")
.when().post("/admin");
String responseBody = response.getBody().asString();

我在 responseBody 中有一个 json:

{"user_id":39}

我可以只使用放心的方法提取到字符串这个值 = 39 吗?

最佳答案

如果您只对提取“user_id”感兴趣,也可以这样做:

String userId = 
given().
contentType("application/json").
body(requestBody).
when().
post("/admin").
then().
statusCode(200).
extract().
path("user_id");

最简单的形式如下:

String userId = get("/person").path("person.userId");

关于java - 放心。是否可以从请求 json 中提取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21166137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com