Restassured +无法解析JSON文档

问题描述 投票:0回答:2

通过可放心的库执行POST时,出现以下错误:-

Restassured +无法解析JSON文档+ groovy.json.JsonException:Lexing在第1行,第1行,第1行失败,同时读取'h',无法识别有效的JSON值或标点符号。

有效负载在“有效负载”类中提到。请帮助我解决此JSON解析问题。我能够成功进行POST,但是在通过Jsonpath类检索数据时,它抛出了错误,该错误在主题行中提到。

package files;

import org.testng.annotations.Test;

import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;

import static io.restassured.RestAssured.*;

public class DynamicJson {

    @Test
    public void addBook(){

        String response1 = RestAssured.baseURI="http://216.10.245.166";
        given().log().all().header("Content-Type","application/json")
        .body(Payload.Addbook())
        .when().post("Library/Addbook.php")
        .then()
        .log().all().assertThat().statusCode(200)
        .extract().response().asString();


        JsonPath js1 = new JsonPath(response1);
        String id = js1.get("ID");
        System.out.println(id);





    }

}

package files;

public class Payload {


    public static String Addbook(){

        String payload = "{\r\n" + 
                "   \"name\":\"Learn Appium Automation with Java\",\r\n" + 
                "   \"isbn\":\"bcd\",\r\n" + 
                "   \"aisle\":\"29k27\",\r\n" + 
                "   \"author\":\"John foe\"\r\n" + 
                "}";
        return payload;

    }
}
json rest-assured jsonparser
2个回答
0
投票

这是一个很小的错误


0
投票

问题是您为response1分配了不正确的值

© www.soinside.com 2019 - 2024. All rights reserved.