gpt4 book ai didi

java - Jayway Rest Assured Json 字符串转换路径

转载 作者:行者123 更新时间:2023-11-29 09:28:49 24 4
gpt4 key购买 nike

我从 API 调用中得到以下响应:

[{"id":63,"name":"Apple Inc.","ticker":"AAPL","website":"www.apple.com","street1":null,"street2":null,"country":null,"postal_code":null,"city":null,"state":null,"type_value":"PUBLIC","person":[{"id":6854208},{"id":6854192},{"id":7795},{"id":6837866},{"id":6854188},{"id":6840774},{"id":6838278},{"id":7637},{"id":6839671},{"id":6837862},{"id":6840759},{"id":6840766},{"id":6838242},{"id":6840830},{"id":6840838},{"id":7875},{"id":3038662},{"id":865765},{"id":6839669},{"id":6837834},{"id":6839685},{"id":6839931},{"id":6840777},{"id":6838232},{"id":6838260},{"id":1859904},{"id":6854204},{"id":6838238},{"id":6839751}],"type":3001,"revenue":null,"industry":[{"industry":"Computer Hardware","industry_id":5009},{"industry":"Electronics","industry_id":5016},{"industry":"Technology - All","industry_id":5044}],"description":null}]

如何从响应中获取名称的值?

这是我现在拥有的:

    System.err.println("fullBspApiUrl"+fullBspApiUrl);
Response resp = get(fullBspApiUrl);
System.err.println("This is response"+resp);
String bJson = resp.asString();
System.err.println("This is response after string conversion"+bJson);
JsonPath jsonpath = new JsonPath(bJson);
System.err.println("Instantiate JsonPath "+jsonpath);
//String bspOrgName = jsonpath.getString("organizationName[0]");
String bspOrgName = jsonpath.getString("organizationName[0]");
System.err.println("This is response after JsonPath string conversion "+bspOrgName);

assertEquals(resp.getStatusCode(),200);
assertEquals(bspOrgName,"Apple Inc");

它返回 Null 而不是 Apple

最佳答案

get(fullBspApiUrl).then().statusCode(200).
and().assertThat().body(name[0], equalTo("Apple Inc"))

关于java - Jayway Rest Assured Json 字符串转换路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32575967/

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