本文整理了Java中com.mashape.unirest.http.JsonNode
类的一些代码示例,展示了JsonNode
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode
类的具体详情如下:
包路径:com.mashape.unirest.http.JsonNode
类名称:JsonNode
暂无
代码示例来源:origin: vulnersCom/burp-vulners-scanner
public void completed(HttpResponse<JsonNode> response) {
JSONObject responseBody = response.getBody().getObject();
if ("ERROR".equals(responseBody.getString("result"))) {
onFail((JSONObject) responseBody.get("data"));
return;
}
onSuccess(responseBody.getJSONObject("data"));
}
代码示例来源:origin: Kong/unirest-java
public RequestBodyEntity body(JsonNode body) {
this.body = body.toString();
return this;
}
代码示例来源:origin: Kong/unirest-java
this.body = (T) new JsonNode(jsonString);
} else if (String.class.equals(responseClass)) {
this.body = (T) new String(rawBody, charset);
代码示例来源:origin: Kaaz/DiscordBot
public String ask(String query) throws UnirestException {
JSONObject jsonOut = new JSONObject();
jsonOut.put("user", user)
.put("key", key)
.put("nick", session)
.put("text", query);
RequestBodyEntity post = Unirest.post("https://cleverbot.io/1.0/ask").header("Content-Type", "application/json")
.body(jsonOut.toString());
JSONObject json = post.asJson().getBody().getObject();
return json.getString("response");
}
}
代码示例来源:origin: Apicurio/apicurio-studio
HttpResponse<com.mashape.unirest.http.JsonNode> response = request.asJson();
JSONObject responseObj = response.getBody().getObject();
if (response.getStatus() != 200) {
throw new UnirestException("Unexpected response from Bitbucket: " + response.getStatus() + "::" + response.getStatusText());
responseObj.getJSONArray("values").forEach(obj -> {
JSONObject b = (JSONObject) obj;
SourceCodeBranch branch = new SourceCodeBranch();
branch.setName(b.getString("name"));
branch.setCommitId(b.getJSONObject("target").getString("hash"));
rVal.add(branch);
});
代码示例来源:origin: Apicurio/apicurio-studio
HttpResponse<JsonNode> response = Unirest.get("https://api.github.com/repos/apicurio/apicurio-studio/releases/tags/v" + oldReleaseTag)
.header("Accept", "application/json").header("Authorization", "token " + githubPAT).asJson();
if (response.getStatus() != 200) {
throw new Exception("Failed to get old release info: " + response.getStatusText());
JsonNode body = response.getBody();
String publishedDate = body.getObject().getString("published_at");
if (publishedDate == null) {
throw new Exception("Could not find Published Date for previous release " + oldReleaseTag);
JSONObject body = new JSONObject();
body.put("tag_name", "v" + releaseTag);
body.put("name", releaseName);
body.put("body", releaseNotes);
assetUploadUrl = response.getBody().getObject().getString("upload_url");
if (assetUploadUrl == null || assetUploadUrl.trim().isEmpty()) {
throw new Exception("Failed to get Asset Upload URL for newly created release!");
JsonNode body = response.getBody();
String publishedDate = body.getObject().getString("published_at");
if (publishedDate == null) {
throw new Exception("Could not find Published Date for release.");
String output = body.getObject().toString(4);
try (FileOutputStream fos = new FileOutputStream(outFile)) {
fos.write(output.getBytes("UTF-8"));
代码示例来源:origin: lamarios/Homedash2
/**
* Query a remote instance for its modules
*/
private Map<String, Object> browseRemote(String url, String key) throws Exception {
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "http://" + url;
}
if (!url.endsWith("/")) {
url += "/";
}
Map<String, Object> remote = new HashMap<>();
remote.put("favourite", get(url).isPresent());
url += "api/browse";
logger.info("Browsing remote: url[{}] key[{}]", url, key);
HttpResponse<JsonNode> response = Unirest.get(url).header(APIController.HEADER_AUTHORIZATION, key).asJson();
remote.put("name", response.getBody().getObject().getString("name"));
List<ExposedModule> modules = new ArrayList<>();
String moduleString = response.getBody().getObject().getJSONArray("modules").toString();
modules = gson.fromJson(moduleString, modules.getClass());
remote.put("modules", modules);
logger.info("Response: \n {}", response.getBody().toString());
return remote;
}
代码示例来源:origin: org.deeplearning4j/gym-java-client
public static <O, A, AS extends ActionSpace<A>> Client<O, A, AS> build(String url, String envId, boolean render) {
JSONObject body = new JSONObject().put("env_id", envId);
JSONObject reply = ClientUtils.post(url + Client.ENVS_ROOT, body).getObject();
String instanceId;
try {
instanceId = reply.getString("instance_id");
} catch (JSONException e) {
throw new RuntimeException("Environment id not found", e);
}
GymObservationSpace<O> observationSpace = fetchObservationSpace(url, instanceId);
AS actionSpace = fetchActionSpace(url, instanceId);
return new Client(url, envId, instanceId, observationSpace, actionSpace, render);
}
代码示例来源:origin: org.deeplearning4j/gym-java-client
/**
* Step the environment by one action
*
* @param action action to step the environment with
* @return the StepReply containing the next observation, the reward, if it is a terminal state and optional information.
*/
public StepReply<O> step(A action) {
JSONObject body = new JSONObject().put("action", getActionSpace().encode(action)).put("render", render);
JSONObject reply = ClientUtils.post(url + ENVS_ROOT + instanceId + STEP, body).getObject();
O observation = observationSpace.getValue(reply, "observation");
double reward = reply.getDouble("reward");
boolean done = reply.getBoolean("done");
JSONObject info = reply.getJSONObject("info");
return new StepReply<O>(observation, reward, done, info);
}
代码示例来源:origin: KocproZ/jenkins-discord
/**
* Send the payload to Discord.
*
* @throws WebhookException the webhook exception
*/
public void send() throws WebhookException {
if (this.embed.toString().length() > 6000)
throw new WebhookException("Embed object larger than the limit (" + this.embed.toString().length() + ">6000).");
this.obj.put("embeds", new JSONArray().put(this.embed));
try {
HttpResponse<JsonNode> response = Unirest.post(this.webhookUrl).header("Content-Type", "application/json").body(this.obj).asJson();
try {
if (response.getBody() == null || response.getBody().getObject().get("embeds") == null) throw new JSONException("Expected.");
throw new WebhookException(response.getBody().getObject().toString(2));
} catch (JSONException ignored) {}
} catch (UnirestException e) { e.printStackTrace(); }
}
}
代码示例来源:origin: bosondata/elasticsearch-analysis-bosonnlp
try {
JSONArray jaTemp = jn.getArray();
if (jaTemp.length() > 0) {
JSONObject jo = jaTemp.getJSONObject(0);
if (jo != null && jo.has("word")) {
JSONArray ja = jo.getJSONArray("word");
new UnirestException(jo.toString()), jo);
throw new RuntimeException("Check validation of API TOKEN or internet: " + jo.toString());
代码示例来源:origin: net.dv8tion/JDA
@Override
public Message sendFile(File file)
{
JDAImpl api = (JDAImpl) getJDA();
try
{
HttpResponse<JsonNode> response = Unirest.post("https://discordapp.com/api/channels/" + getId() + "/messages")
.header("authorization", getJDA().getAuthToken())
.header("user-agent", JDAInfo.GITHUB + " " + JDAInfo.VERSION)
.field("file", file)
.asJson();
JSONObject messageJson = new JSONObject(response.getBody().toString());
return new EntityBuilder(api).createMessage(messageJson);
}
catch (UnirestException e)
{
e.printStackTrace();
return null;
}
}
代码示例来源:origin: hujiaweibujidao/Ganks-for-gank.io
private List<GankItem> loadGankIOItemsWithIssue(GankIssue issue) throws UnirestException {
logger.info("load items from issue: " + issue.getTitle());
List<GankItem> items = new ArrayList<GankItem>();
String urlSuffix = issue.getId().replaceAll("-", "/");
HttpResponse<JsonNode> jsonResponse = Unirest.get(API_GANKS + urlSuffix).asJson();
JSONObject jsonObject = jsonResponse.getBody().getObject();
JSONArray categories = jsonObject.getJSONArray("category");
JSONObject results = jsonObject.getJSONObject("results");
for (int i = 0; i < categories.length(); i++) {
JSONArray array = results.getJSONArray(categories.getString(i));
for (int j = 0; j < array.length(); j++) {
GankItem item = parseItem(array.getJSONObject(j), issue);
if (null != item) items.add(item);
}
}
return items;
}
代码示例来源:origin: DiUS/pact-workshop-jvm
public List<Object> fetchAndProcessData(String dateTime) throws UnirestException {
Optional<JsonNode> data = loadProviderJson(dateTime);
System.out.println("data=" + data);
if (data != null && data.isPresent()) {
JSONObject jsonObject = data.get().getObject();
int value = 100 / jsonObject.getInt("count");
OffsetDateTime date = OffsetDateTime.parse(jsonObject.getString("validDate"),
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX"));
System.out.println("value=" + value);
System.out.println("date=" + date);
return Arrays.asList(value, date);
} else {
return Arrays.asList(0, null);
}
}
}
代码示例来源:origin: org.deeplearning4j/gym-java-client
/**
* Reset the state of the environment and return an initial observation.
*
* @return initial observation
*/
public O reset() {
JsonNode resetRep = ClientUtils.post(url + ENVS_ROOT + instanceId + RESET, new JSONObject());
return observationSpace.getValue(resetRep.getObject(), "observation");
}
代码示例来源:origin: simplesteph/medium-blog-kafka-udemy
public ReviewApiResponse reviewApi(Integer pageSize, Integer page) throws HttpException {
String url = "https://www.udemy.com/api-2.0/courses/" + courseId + "/reviews";
HttpResponse<JsonNode> jsonResponse = null;
try {
jsonResponse = Unirest.get(url)
.queryString("page", page)
.queryString("page_size", pageSize)
.queryString("fields[course_review]", "title,content,rating,created,modified,user_modified,user,course")
.asJson();
} catch (UnirestException e) {
throw new HttpException(e.getMessage());
}
if (jsonResponse.getStatus() == 200) {
JSONObject body = jsonResponse.getBody().getObject();
Integer count = body.getInt("count");
String next = body.optString("next");
String previous = body.optString("previous");
List<Review> reviews = this.convertResults(body.getJSONArray("results"));
ReviewApiResponse reviewApiResponse = new ReviewApiResponse(count, next, previous, reviews);
return reviewApiResponse;
}
throw new HttpException("Udemy API Unavailable");
}
代码示例来源:origin: artex-development/Lukkit
/**
* Check for updates against the GitHub repo releases page.
*
* @param pluginVersion the locally installed plugin version
*/
public static void checkForUpdates(String pluginVersion) {
try {
HttpResponse<JsonNode> res = Unirest.get("https://api.github.com/repos/" + GITHUB_ORG + "/Lukkit/releases/latest").asJson();
String tagName = res.getBody().getObject().getString("tag_name").replace("v", "");
if (isOutOfDate(pluginVersion.split("-")[0], tagName)) {
Main.logger.info("A new version of Lukkit has been released: " + tagName);
Main.logger.info("You can download it from https://www.spigotmc.org/resources/lukkit.32599/ or https://github.com/jammehcow/Lukkit/releases");
} else {
Main.logger.info("You're up to date with the latest version of Lukkit.");
}
} catch (Exception e ) { e.printStackTrace(); }
}
代码示例来源:origin: simplesteph/kafka-connect-github-source
Headers headers = jsonResponse.getHeaders();
XRateLimit = Integer.valueOf(headers.getFirst("X-RateLimit-Limit"));
XRateRemaining = Integer.valueOf(headers.getFirst("X-RateLimit-Remaining"));
XRateReset = Integer.valueOf(headers.getFirst("X-RateLimit-Reset"));
switch (jsonResponse.getStatus()){
case 200:
return jsonResponse.getBody().getArray();
case 401:
throw new ConnectException("Bad GitHub credentials provided, please edit your config");
case 403:
log.info(jsonResponse.getBody().getObject().getString("message"));
log.info(String.format("Your rate limit is %s", XRateLimit));
log.info(String.format("Your remaining calls is %s", XRateRemaining));
log.error(constructUrl(page, since));
log.error(String.valueOf(jsonResponse.getStatus()));
log.error(jsonResponse.getBody().toString());
log.error(jsonResponse.getHeaders().toString());
log.error("Unknown error: Sleeping 5 seconds " +
代码示例来源:origin: Apicurio/apicurio-studio
HttpResponse<JsonNode> response = Unirest.get(currentPageUrl)
.header("Accept", "application/json").header("Authorization", "token " + githubPAT).asJson();
if (response.getStatus() != 200) {
throw new Exception("Failed to list Issues: " + response.getStatusText());
JSONArray issueNodes = response.getBody().getArray();
issueNodes.forEach(issueNode -> {
JSONObject issue = (JSONObject) issueNode;
String closedOn = issue.getString("closed_at");
if (since.compareTo(closedOn) < 0) {
rval.add(issue);
代码示例来源:origin: org.streampipes/streampipes-app-file-export
.body("{\"from\" : 0, \"size\" : 10000, \"query\": {\"range\" : {\"timestamp\" : {\"gte\" : " + timestampFrom + ",\"lte\" : " + timeStampTo + "}}}}")
.asJson();
String response = jsonResponse.getBody().getObject().toString();
内容来源于网络,如有侵权,请联系作者删除!