本文整理汇总了Java中com.mashape.unirest.request.HttpRequest.asJson方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest.asJson方法的具体用法?Java HttpRequest.asJson怎么用?Java HttpRequest.asJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mashape.unirest.request.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.asJson方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeQuery
import com.mashape.unirest.request.HttpRequest; //导入方法依赖的package包/类
private String makeQuery(String query, boolean includeObsoletes) {
HttpRequest req = formQueryRequest(query, includeObsoletes);
HttpResponse<JsonNode> resp = null;
String uri = null;
try {
resp = req.asJson();
} catch (UnirestException e) {
throw new RuntimeException(e);
}
if (resp.getStatus() == 200) {
uri = findTermUri(resp.getBody());
}
logger.info("Found term URI {} for {}", uri, query);
return uri;
}
示例2: retriveFromStack
import com.mashape.unirest.request.HttpRequest; //导入方法依赖的package包/类
private String retriveFromStack(String question) throws UnirestException {
HttpRequest request = Unirest.get(STACK_API_PATH)
.queryString("q", "\"" + question + "\"")
.queryString("site", "stackoverflow")
.queryString("sort", "relevance");
log.info("Asking for {}", question);
HttpResponse<JsonNode> stackResponse = request.asJson();
log.info("Stack response: {}", stackResponse.getBody().toString());
JSONObject jsonLink = stackResponse.getBody().getObject().getJSONArray("items").getJSONObject(1);
String response = jsonLink.getString("link").toString();
log.info("Got answer {}", response);
return response;
}
示例3: retrieve
import com.mashape.unirest.request.HttpRequest; //导入方法依赖的package包/类
public JSONArray retrieve(Set<String> batchIds) throws UnirestException {
HttpRequest prequery = prebuild(RETRIEVE);
for (String batchId : batchIds) {
prequery = prequery.queryString("batch_id", batchId);
}
HttpResponse<JsonNode> response = prequery.asJson();
return response.getBody().getObject().getJSONArray("documents");
}
示例4: getGamesListNames
import com.mashape.unirest.request.HttpRequest; //导入方法依赖的package包/类
/**
* Gets list of games available on hitbox.tv
*
* @param limit
* limit of list elements
* @param liveOnly
* shows only live games
* @param keywords
* show games with this keywords
* @return {@link List} of games names
* @throws Exception
*/
public List<String> getGamesListNames(int limit, boolean liveOnly,
String... keywords) throws Exception {
RequestHandler req = RequestHandler.instance();
Params p = new Params().p("limit", limit).p("liveonly", liveOnly);
if (keywords != null && keywords.length > 0) {
StringBuilder sb = new StringBuilder();
for (String key : keywords) {
sb.append(key);
}
p = p.p("q", sb.toString());
}
HttpRequest request = req.get(HbGet.GAMES_LIST, p);
HttpResponse<JsonNode> httpResponse = request.asJson();
JsonNode node = httpResponse.getBody();
JSONObject gamesJson = node.getObject();
JSONArray gamesArray = gamesJson.getJSONArray("categories");
ArrayList<String> games = new ArrayList<>();
for (int i = 0; i < gamesArray.length(); i++) {
if (gamesArray.get(i) == null) {
continue;
}
JSONObject catElem = gamesArray.getJSONObject(i);
if (catElem.isNull("category_name")) {
continue;
}
String catName = catElem.getString("category_name");
if (catName == null || catName == "") {
continue;
}
games.add(catName);
}
return games;
}