本文整理汇总了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;
}
示例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;
}
示例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");
}
}
示例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");
}
}
示例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");
}
}
示例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");
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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");
}