本文整理了Java中com.mashape.unirest.http.JsonNode.getObject()
方法的一些代码示例,展示了JsonNode.getObject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.getObject()
方法的具体详情如下:
包路径:com.mashape.unirest.http.JsonNode
类名称:JsonNode
方法名:getObject
暂无
代码示例来源: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: flekschas/owl2neo4j
private static void checkForError (HttpResponse<JsonNode> response) throws Exception {
JSONObject jsonResponse = response.getBody().getObject();
JSONArray errors = (JSONArray) jsonResponse.get("errors");
if (errors.length() > 0) {
JSONObject error = (JSONObject) errors.get(0);
String errorMsg = error.get("code").toString() + ": \"" + error.get("message").toString() + "\"";
throw new Exception(errorMsg);
}
}
代码示例来源: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: IQSS/dataverse
/**
* transfer script from DCM
*/
public static ScriptRequestResponse getScriptFromRequest(HttpResponse<JsonNode> uploadRequest) {
int status = uploadRequest.getStatus();
JsonNode body = uploadRequest.getBody();
logger.fine("Got " + status + " with body: " + body);
if (status == 404) {
return new ScriptRequestResponse(status);
}
int httpStatusCode = uploadRequest.getStatus();
String script = body.getObject().getString("script");
String datasetIdentifier = body.getObject().getString("datasetIdentifier");
long userId = body.getObject().getLong("userId");
ScriptRequestResponse scriptRequestResponse = new ScriptRequestResponse(httpStatusCode, datasetIdentifier, userId, script);
return scriptRequestResponse;
}
代码示例来源:origin: hujiaweibujidao/Ganks-for-gank.io
public List<GankIssue> loadGankIOIssues() throws UnirestException {
List<GankIssue> issues = new ArrayList<GankIssue>();
HttpResponse<JsonNode> jsonResponse = Unirest.get(API_DATES).asJson();
JSONObject jsonObject = jsonResponse.getBody().getObject();
JSONArray results = jsonObject.getJSONArray("results");
int len = results.length();
for (int i = 0; i < len; i++) {
issues.add(parseIssue(results.getString(i), len - i));
}
return issues;
}
代码示例来源: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: thejamesthomas/javabank
public boolean isMountebankAllowingInjection() {
try {
HttpResponse<JsonNode> response = Unirest.get(baseUrl + "/config").asJson();
return response.getBody().getObject().getJSONObject("options").getBoolean("allowInjection");
} catch (UnirestException e) {
return false;
}
}
代码示例来源:origin: thejamesthomas/javabank
public int getImposterCount() {
try {
HttpResponse<JsonNode> response = Unirest.get(baseUrl + "/imposters").asJson();
return ((JSONArray) response.getBody().getObject().get("imposters")).length();
} catch (UnirestException e) {
return -1;
}
}
代码示例来源: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: lamarios/Homedash2
public static PlexSession parseJson(JsonNode node) {
PlexSession plexSession = new PlexSession();
JSONObject mediaContainerJSON = node.getObject().getJSONObject("MediaContainer");
plexSession.setMediaContainer(MediaContainer.fromJson(mediaContainerJSON));
return plexSession;
}
}
代码示例来源:origin: Kaaz/DiscordBot
/**
* dumps a string to hastebin
*
* @param message the text to send
* @return key how to find it
*/
private static String handleHastebin(String message) throws UnirestException {
return Unirest.post("https://hastebin.com/documents").body(message).asJson().getBody().getObject().getString("key");
}
}
代码示例来源:origin: baloise/rocket-chat-rest-client
private void login() throws IOException {
HttpResponse<JsonNode> loginResult;
try {
loginResult = Unirest.post(serverUrl + "v1/login").field("username", user).field("password", password).asJson();
} catch (UnirestException e) {
throw new IOException(e);
}
if (loginResult.getStatus() == 401)
throw new IOException("The username and password provided are incorrect.");
if (loginResult.getStatus() != 200)
throw new IOException("The login failed with a result of: " + loginResult.getStatus());
JSONObject data = loginResult.getBody().getObject().getJSONObject("data");
this.authToken = data.getString("authToken");
this.userId = data.getString("userId");
}
代码示例来源:origin: ContainerSolutions/minimesos
@Override
public Boolean call() throws Exception {
try {
Unirest.get(getServiceUrl().toString() + APPS_ENDPOINT).header(HEADER_ACCEPT, APPLICATION_JSON).asJson().getBody().getObject();
} catch (UnirestException e) { //NOSONAR
// meaning API is not ready
return false;
}
return true;
}
}
代码示例来源:origin: ContainerSolutions/minimesos
@Override
public JSONObject getStateInfoJSON() throws UnirestException {
String stateUrl = getStateUrl();
GetRequest request = Unirest.get(stateUrl);
HttpResponse<JsonNode> response = request.asJson();
return response.getBody().getObject();
}
代码示例来源:origin: thejamesthomas/javabank
@Test
public void shouldCountTheNumberOfImposters() throws UnirestException {
JsonNode jsonNode = mock(JsonNode.class);
JSONObject jsonObject = mock(JSONObject.class);
JSONArray jsonArray = mock(JSONArray.class);
when(Unirest.get(Client.DEFAULT_BASE_URL + "/imposters")).thenReturn(getRequest);
when(getRequest.asJson()).thenReturn(httpResponse);
when(httpResponse.getBody()).thenReturn(jsonNode);
when(jsonNode.getObject()).thenReturn(jsonObject);
when(jsonObject.get("imposters")).thenReturn(jsonArray);
when(jsonArray.length()).thenReturn(Integer.valueOf(3));
assertThat(client.getImposterCount()).isEqualTo(3);
}
代码示例来源:origin: zackpollard/JavaTelegramBot-API
public static UserProfilePhotos createUserProfilePhotos(long user_id, TelegramBot telegramBot) {
try {
JSONObject json = Unirest.post(telegramBot.getBotAPIUrl() + "getUserProfilePhotos")
.queryString("user_id", user_id).asJson().getBody().getObject();
if(json.getBoolean("ok")) {
return new UserProfilePhotosImpl(json.getJSONObject("result"));
}
} catch (UnirestException e) {
e.printStackTrace();
}
return null;
}
代码示例来源:origin: Kaaz/DiscordBot
@Override
public String execute(DiscordBot bot, String[] args, MessageChannel channel, User author, Message inputMessage) {
try {
String tags = "";
if (args.length > 0) {
tags = "&tag=" + Joiner.on("+").join(args);
}
HttpResponse<JsonNode> response = Unirest.get("http://api.giphy.com/v1/gifs/random?api_key=" + BotConfig.GIPHY_TOKEN + tags).asJson();
return response.getBody().getObject().getJSONObject("data").getString("url");
} catch (Exception ignored) {
//this exception is about as useful as a nipple on a male
}
return Templates.command.gif_not_today.formatGuild(channel);
}
}
代码示例来源:origin: thejamesthomas/javabank
@Test
public void assertThatMountebankAllowsInjection() throws UnirestException {
JSONObject jsonObjectOptions = mock(JSONObject.class);
JSONObject jsonObjectAllowInjection = mock(JSONObject.class);
when(Unirest.get(Client.DEFAULT_BASE_URL + "/config")).thenReturn(getRequest);
when(getRequest.asJson()).thenReturn(httpResponse);
when(httpResponse.getBody()).thenReturn(value);
when(value.getObject()).thenReturn(jsonObjectOptions);
when(jsonObjectOptions.getJSONObject("options")).thenReturn(jsonObjectAllowInjection);
when(jsonObjectAllowInjection.getBoolean("allowInjection")).thenReturn(Boolean.TRUE);
if (!client.isMountebankAllowingInjection()) {
fail("Mountebank is not running with --allowInjection!");
}
}
代码示例来源:origin: org.deeplearning4j/gym-java-client
static public JSONObject get(String url) {
HttpResponse<JsonNode> jsonResponse = null;
try {
jsonResponse = Unirest.get(url).header("content-type", "application/json").asJson();
} catch (UnirestException e) {
unirestCrash(e);
}
checkReply(jsonResponse, url);
return jsonResponse.getBody().getObject();
}
内容来源于网络,如有侵权,请联系作者删除!