當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonNode.getObject方法代碼示例

本文整理匯總了Java中com.mashape.unirest.http.JsonNode.getObject方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonNode.getObject方法的具體用法?Java JsonNode.getObject怎麽用?Java JsonNode.getObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mashape.unirest.http.JsonNode的用法示例。


在下文中一共展示了JsonNode.getObject方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAsJSONObject

import com.mashape.unirest.http.JsonNode; //導入方法依賴的package包/類
/**
 * @return The json object get by performing request.
 */
public JSONObject getAsJSONObject() {
    JSONObject json;
    try {
        HttpResponse<JsonNode> response = request.asJson();
        checkRateLimit(response);
        handleErrorCode(response);
        JsonNode node = response.getBody();

        if (node.isArray()) {
            throw new UnirestException("The request returns a JSON Array. Json: "+node.getArray().toString(4));
        } else {
            json = node.getObject();
        }
    } catch (UnirestException e) {
        throw new JSONException("Error Occurred while getting JSON Object: "+e.getLocalizedMessage());
    }
    handleErrorResponse(json);
    return json;
}
 
開發者ID:AlienIdeology,項目名稱:J-Cord,代碼行數:23,代碼來源:Requester.java

示例2: parse

import com.mashape.unirest.http.JsonNode; //導入方法依賴的package包/類
public <T> Results<T> parse(JsonNode jsonNode, Class<? extends ApiObject> apiObject) {
    LOGGER.debug("Parsing JSON node");

    final Results<T> results = new Results<>();
    final JSONObject root = jsonNode.getObject();
    results.setPage(root.getInt("current_page"));
    results.setTotal(root.getInt("total_entries"));
    results.setRawResults(jsonNode.toString());
    final JSONArray rso = root.getJSONArray("results");

    if (Product.class == apiObject) {
        results.setResults(parseProducts(rso));
    } else if (Vendor.class == apiObject) {
        results.setResults(parseVendors(rso));
    } else if (Version.class == apiObject) {
        results.setResults(parseVersions(rso));
    } else if (Vulnerability.class == apiObject) {
        results.setResults(parseVulnerabilities(rso));
    }
    return results;
}
 
開發者ID:stevespringett,項目名稱:vulndb-data-mirror,代碼行數:22,代碼來源:VulnDbParser.java

示例3: postRequest

import com.mashape.unirest.http.JsonNode; //導入方法依賴的package包/類
/**
 * POST request using UniRest library.
 *
 * @param url is endpoint to which request has to be done.
 * @param params is data that has to be sent in body.
 * @return JSONObject returns json response.
 * @throws KiteException contains error message and error code inside.
 * @throws JSONException occurs when there is error while parsing data.
 */

public JSONObject postRequest(String url, Map<String, Object> params) throws KiteException, JSONException {
    try {
        if(KiteConnect.httpHost != null){
            Unirest.setProxy(KiteConnect.httpHost);
        }
        HttpResponse<JsonNode> response = Unirest.post(url)
                .header("accept", "application/json")
                .fields(params)
                .asJson();

        JsonNode body = response.getBody();
        JSONObject jsonObject = body.getObject();
        int code = response.getStatus();

        if (code == 200)
            return jsonObject;
        else
            throw dealWithKiteException(body, code);

    } catch (UnirestException e) {
       throw new KiteNoNetworkException("Connection error");
    }

}
 
開發者ID:zerodhatech,項目名稱:javakiteconnect,代碼行數:35,代碼來源:KiteRequest.java

示例4: getRequest

import com.mashape.unirest.http.JsonNode; //導入方法依賴的package包/類
/**
 * GET request using UniRest library.
 *
 * @param url is endpoint to which request has to be done.
 * @param params is data that has to be sent.
 * @return JSONObject returns json response.
 * @throws KiteException contains error message and error code inside.
 * @throws JSONException occurs when there is error while parsing data.
 */
public JSONObject getRequest(String url, Map<String, Object> params) throws KiteException, JSONException {

    try {
        if(KiteConnect.httpHost != null){
            Unirest.setProxy(KiteConnect.httpHost);
        }
        HttpResponse<JsonNode> response = Unirest.get(url).queryString(params)
                .header("accept", "application/json")
                .asJson();
        JsonNode body = response.getBody();
        JSONObject jsonObject = body.getObject();
        int code = response.getStatus();

        if (code == 200)
            return jsonObject;
        else
            throw dealWithKiteException(body, code);

    } catch (UnirestException e) {
       throw new KiteNoNetworkException("Connection error");
    }
}
 
開發者ID:zerodhatech,項目名稱:javakiteconnect,代碼行數:32,代碼來源:KiteRequest.java

示例5: putRequest

import com.mashape.unirest.http.JsonNode; //導入方法依賴的package包/類
/**
 * PUT request.
 * @param url is endpoint to which request has to be done.
 * @param params is data that has to be sent.
 * @return JSONObject returns json response.
 * @throws KiteException contains error message and error code inside.
 * @throws JSONException occurs when there is error while parsing data.
 */
public JSONObject putRequest(String url, Map<String, Object> params) throws KiteException, JSONException {

    try {
        if(KiteConnect.httpHost != null){
            Unirest.setProxy(KiteConnect.httpHost);
        }
        HttpResponse<JsonNode> response = Unirest.put(url)
                .header("accept", "application/json")
                .fields(params)
                .asJson();
        JsonNode body = response.getBody();
        JSONObject jsonObject = body.getObject();
        int code = response.getStatus();

        if (code == 200)
            return jsonObject;
        else
            throw dealWithKiteException(body, code);

    } catch (UnirestException e) {
        throw new KiteNoNetworkException("Connection error");
    }


}
 
開發者ID:zerodhatech,項目名稱:javakiteconnect,代碼行數:34,代碼來源:KiteRequest.java

示例6: deleteRequest

import com.mashape.unirest.http.JsonNode; //導入方法依賴的package包/類
/**
 * DELETE request.
 * @param url is endpoint to which request has to be done.
 * @param params is data that has to be sent.
 * @return JSONObject returns json response.
 * @throws KiteException contains error message and error code inside.
 * @throws JSONException occurs when there is error while parsing data.
 */
public JSONObject deleteRequest(String url, Map<String, Object> params) throws KiteException, JSONException {

    try {
        if(KiteConnect.httpHost != null){
            Unirest.setProxy(KiteConnect.httpHost);
        }
        HttpResponse<JsonNode> response = Unirest.delete(url).queryString(params)
                .header("accept", "application/json")
                .asJson();
        JsonNode body = response.getBody();
        JSONObject jsonObject = body.getObject();
        int code = response.getStatus();

        if (code == 200)
            return jsonObject;
        else
            throw dealWithKiteException(body, code);

    } catch (UnirestException e) {
        throw new KiteNoNetworkException("Connection error");
    }

}
 
開發者ID:zerodhatech,項目名稱:javakiteconnect,代碼行數:32,代碼來源:KiteRequest.java

示例7: createPlaylist

import com.mashape.unirest.http.JsonNode; //導入方法依賴的package包/類
private static JSONObject createPlaylist(String spotifyId, String title, String authHeader) {
    HttpRequestWithBody http =
            Unirest.post("https://api.spotify.com/v1/users/" + spotifyId + "/playlists");

    try {
        HttpResponse<JsonNode> httpResponse = http
                .header("Content-Type", "application/json")
                .header("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36")
                .header("Authorization", authHeader)
                .body("{\"name\":\"" + title + "\", \"public\":true}")
                .asJson();

        JsonNode response = httpResponse.getBody();
        return response.getObject();
    } catch (Exception e) {
        e.printStackTrace();
        throw new WrapperException();
    }
}
 
開發者ID:jiaweizhang,項目名稱:spotify-pull-requests,代碼行數:20,代碼來源:PlaylistService.java

示例8: createCollaborativePlaylist

import com.mashape.unirest.http.JsonNode; //導入方法依賴的package包/類
public static JSONObject createCollaborativePlaylist(String spotifyId, String title, String authHeader) {
    HttpRequestWithBody http =
            Unirest.post("https://api.spotify.com/v1/users/" + spotifyId + "/playlists");

    try {
        HttpResponse<JsonNode> httpResponse = http
                .header("Content-Type", "application/json")
                .header("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36")
                .header("Authorization", authHeader)
                .body("{\"name\":\"" + title + "\", \"public\":false, \"collaborative\":true}")
                .asJson();

        JsonNode response = httpResponse.getBody();
        return response.getObject();
    } catch (Exception e) {
        e.printStackTrace();
        throw new WrapperException();
    }
}
 
開發者ID:jiaweizhang,項目名稱:spotify-pull-requests,代碼行數:20,代碼來源:PlaylistService.java

示例9: parseStatus

import com.mashape.unirest.http.JsonNode; //導入方法依賴的package包/類
public Status parseStatus(JsonNode jsonNode) {
    LOGGER.debug("Parsing JSON node");

    final Status status = new Status();
    final JSONObject root = jsonNode.getObject();
    status.setOrganizationName(root.optString("organization_name"));
    status.setUserNameRequesting(root.optString("user_name_requesting"));
    status.setUserEmailRequesting(root.optString("user_email_address_requesting"));
    status.setSubscriptionEndDate(root.optString("subscription_end_date"));
    status.setApiCallsAllowedPerMonth(root.optString("number_of_api_calls_allowed_per_month"));
    status.setApiCallsMadeThisMonth(root.optString("number_of_api_calls_made_this_month"));
    status.setVulnDbStatistics(root.optString("vulndb_statistics"));
    status.setRawStatus(jsonNode.toString());
    return status;
}
 
開發者ID:stevespringett,項目名稱:vulndb-data-mirror,代碼行數:16,代碼來源:VulnDbParser.java

示例10: findTermUri

import com.mashape.unirest.http.JsonNode; //導入方法依賴的package包/類
protected String findTermUri(JsonNode node) {

        Assert.notNull(node);
        Assert.isTrue(!node.isArray());

        JSONObject jsonObject = node.getObject();

        JSONObject response = jsonObject.getJSONObject("response");

        Assert.notNull(response);

        Assert.isTrue(response.has("numFound"));

        int numFound = response.getInt("numFound");

        if (numFound < 1) {
            return null;
        }

        Assert.isTrue(response.has("docs"));

        JSONArray docs = response.getJSONArray("docs");

        Assert.notNull(docs);
        JSONObject doc = docs.getJSONObject(0);

        return doc.getString("iri");
    }
 
開發者ID:EMBL-EBI-SUBS-OLD,項目名稱:subs,代碼行數:29,代碼來源:OlsSearchServiceImpl.java


注:本文中的com.mashape.unirest.http.JsonNode.getObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。