我如何解析JSON响应,并可以从已知键作为输出获取值?



我的代码如下,我尝试使用JSONOption,但它没有工作

Response res =  (Response) RestAssured.given().queryParam("CUSTOMER_ID","68195").queryParam("PASSWORD","1234!").queryParam("Account_No","1").get("http://demo.guru99.com/V4/sinkministatement.php").then().extract().response();
System.out.println(res.body().asString());
        
        JSONObject jsonBody = new JSONObject(res.prettyPrint());
       System.out.println(jsonBody);

我可以用PreetyPrint方法获得JSON Body,但无法从该响应中获取键值对。似乎我需要解析body方法的输出。

在https://github.com/fiatjaf/jq-web有一个叫做JQ和JS实现的命令工具。

示例用法:

var jq = require('jq-web')
var result = jq.json({...}, 'select(.CUSTOMER_ID="123")');

尝试HttpClient的GetMethod.

private static HttpClient httpClient;
       
    public void getTest() {
          GetMethod request = new GetMethod("http://demo.guru99.com/V4/sinkministatement.php" +
                "?CUSTOMER_ID=68195" + 
                "&PASSWORD=1234" +
                "&Account_No=1");
            try {
                int result = httpClient.executeMethod(request);
                String responseContent = request.getResponseBodyAsString();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }

最新更新