英文:
Get Value and pass as parameter to function in Java
问题
ResponseEntity<String> respEntity = null;
try {
respEntity = getConfiguredRestTemplate().exchange(uri.toString()
, HttpMethod.GET
, entity
, new ParameterizedTypeReference<String>() {
});
log.debug("URL to retrieve a document : {}", respEntity.getBody());
}
// The respEntity.getBody() returns {"url":"https://aps-fst"}
// I want to send only the value - https://aps-fst as parameter to a function
// to download the content in the URL. How to extract only the URL value and
// pass it as parameter of type URL / String ?
英文:
ResponseEntity<String> respEntity = null;
try {
respEntity = getConfiguredRestTemplate().exchange(uri.toString()
, HttpMethod.GET
, entity
, new ParameterizedTypeReference<String>() {
});
log.debug("URL to retrieve a document : {}", respEntity.getBody());
}
The respEntity.getBody() returns {"url":"https://aps-fst"}
I want to send only the value - https://aps-fst as parameter to a function to download the content in the URL. How to extract only the URL value and pass it as parameter of type URL / String ?
答案1
得分: 0
你可以使用 jackson 中的 ObjectMapper,将响应体转换为一个映射(map),从中可以取出 url 的值。你可以在这里找到一个示例:链接。
英文:
You can use ObjectMapper from jackson and have the response body transformed into a map from which you can take the url value. You can find an example here.
答案2
得分: -1
String jsonString = respEntity.getBody();
JSONObject obj = new JSONObject(jsonString);
String s3urlvalue = obj.getString("url");
log.debug("S3 URL to retrieve a document : {}", s3urlvalue);
我能够通过上述代码获得值。
英文:
String jsonString = respEntity.getBody();
JSONObject obj = new JSONObject(jsonString);
String s3urlvalue = obj.getString("url");
log.debug("S3 URL to retrieve a document : {} ", s3urlvalue);
I am able to get value with above code
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论