当前位置: 首页>>代码示例>>Java>>正文


Java HttpRequest.asJson方法代码示例

本文整理汇总了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;
}
 
开发者ID:EMBL-EBI-SUBS-OLD,项目名称:subs,代码行数:20,代码来源:OlsSearchServiceImpl.java

示例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;
}
 
开发者ID:TouK,项目名称:janusz,代码行数:17,代码来源:StackOverflowCommand.java

示例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");
}
 
开发者ID:textocat,项目名称:textocat-java-sdk,代码行数:9,代码来源:EntityHttpService.java

示例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;
}
 
开发者ID:GRM-dev,项目名称:HitBoard,代码行数:46,代码来源:Games.java


注:本文中的com.mashape.unirest.request.HttpRequest.asJson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。