问题
I am getting the following exception while trying to Automate an API: Exception in thread "main" io.restassured.path.json.exception.JsonPathException: Failed to parse the JSON document at io.restassured.path.json.JsonPath$ExceptionCatcher.invoke(JsonPath.java:1002) at io.restassured.path.json.JsonPath$4.doParseWith(JsonPath.java:967) at io.restassured.path.json.JsonPath$JsonParser.parseWith(JsonPath.java:1047) at io.restassured.path.json.JsonPath.toJsonString(JsonPath.java:1064) at io.restassured.path.json.JsonPath.prettify(JsonPath.java:685) at io.restassured.path.json.JsonPath.prettyPrint(JsonPath.java:700) at ApiAutomation_BDD.ApiAutomation_BDD.bearerToken_GETRequest.main(bearerToken_GETRequest.java:35) Caused by: groovy.json.JsonException: Lexing failed on line: 2, column: 1, while reading '<', no possible valid JSON value or punctuation could be recognized. at groovy.json.JsonLexer.nextToken(JsonLexer.java:86) at groovy.json.JsonLexer$nextToken.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130) at io.restassured.internal.path.json.ConfigurableJsonSlurper.parse(ConfigurableJsonSlurper.groovy:97) at io.restassured.internal.path.json.ConfigurableJsonSlurper$parse.callCurrent(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:185) at io.restassured.internal.path.json.ConfigurableJsonSlurper.parseText(ConfigurableJsonSlurper.groovy:83) at io.restassured.path.json.JsonPath$4$1.method(JsonPath.java:965) at io.restassured.path.json.JsonPath$ExceptionCatcher.invoke(JsonPath.java:1000) ... 6 more
and the following is the code which I tried (again not sharing any values coz of security risk):
public static void main(String args[]) throws IOException {
RestAssured.baseURI = "{Url}";
RequestSpecification httpRequest = RestAssured.given()
.contentType("x-www-form-urlencoded")
.formParam("grant_type", "")
.formParam("client_id", "")
.formParam("scope", "")
.formParam("client_secret","");
Response response = httpRequest.request(Method.GET);
JsonPath res = response.jsonPath();
//String BearerToken = response.getBody().asString();
//System.out.println("The response is:" +res);
res.prettyPrint();
int code = response.getStatusCode();
System.out.println("The status code is" + code);
assertEquals(code, 200);
} }
来源:https://stackoverflow.com/questions/65578133/exception-in-thread-main-io-restassured-path-json-exception-jsonpathexception