[英]How can I parse the JSON response and could get value from known key as output?
My code is as below, I tried using JSONOption but it did not work我的代码如下,我尝试使用 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);
I can get JSON Body with PreetyPrint method but could not fetch key-value pair from that response.我可以使用 PreetyPrint 方法获取 JSON Body 但无法从该响应中获取键值对。 Seems like I need to parse output of body method.好像我需要解析 body 方法的 output 。
There is a command tool called JQ and JS implementation at https://github.com/fiatjaf/jq-web .在https://github.com/fiatjaf/jq-web上有一个名为JQ和 JS implementation 的命令工具。
Sample usage:示例用法:
var jq = require('jq-web')
var result = jq.json({...}, 'select(.CUSTOMER_ID="123")');
Try HttpClient's GetMethod.试试 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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.