Refine search
@Override void write(JsonWriter writer) throws IOException { writer.writeArrayOpen(); Iterator<JsonValue> iterator = iterator(); if (iterator.hasNext()) { iterator.next().write(writer); while (iterator.hasNext()) { writer.writeArraySeparator(); iterator.next().write(writer); } } writer.writeArrayClose(); }
/** * Creates a new JsonArray that contains the JSON representations of the given strings. * * @param strings * the strings to be included in the new JSON array * @return a new JSON array that contains the given strings */ public static JsonArray array(String... strings) { if (strings == null) { throw new NullPointerException("values is null"); } JsonArray array = new JsonArray(); for (String value : strings) { array.add(value); } return array; }
public synchronized String getSuccessfulOperationTXID(String opID) throws WalletCallException, IOException, InterruptedException { String TXID = null; JsonArray response = this.executeCommandAndGetJsonArray( "z_getoperationstatus", wrapStringParameter("[\"" + opID + "\"]")); JsonObject jsonStatus = response.get(0).asObject(); JsonValue opResultValue = jsonStatus.get("result"); if (opResultValue != null) { JsonObject opResult = opResultValue.asObject(); if (opResult.get("txid") != null) { TXID = opResult.get("txid").asString(); } } return TXID; }
JsonObject toArgument = new JsonObject(); toArgument.set("address", to); if (hexMemo.length() >= 2) { toArgument.set("memo", hexMemo.toString()); toArgument.set("amount", "\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF"); JsonArray toMany = new JsonArray(); toMany.add(toArgument); String toManyBeforeReplace = toMany.toString(); int firstIndex = toManyBeforeReplace.indexOf(amountPattern); int lastIndex = toManyBeforeReplace.lastIndexOf(amountPattern); String toManyArrayStr = toMany.toString().replace( amountPattern, "\"amount\":" + new DecimalFormat("########0.00######", decSymbols).format(Double.valueOf(amount))); JsonArray toManyVerificationArr = Json.parse(toManyArrayStr).asArray(); BigDecimal bdFinalAmount = new BigDecimal(toManyVerificationArr.get(0).asObject().getDouble("amount", -1)); BigDecimal difference = bdAmout.subtract(bdFinalAmount).abs(); if (difference.compareTo(new BigDecimal("0.000000015")) >= 0) {
public void load() throws ConnectionException { String uuid = id.substring(3); // trims the string "28:" JsonObject root = Endpoints.AGENT_INFO.open(skype, uuid) .expect(200, "While fetching agent info") .as(JsonObject.class) .get(); JsonArray descriptions = root.get("agentDescriptions").asArray(); if (descriptions.size() > 1) { throw Skype.UNEXPECTED; } JsonObject object = descriptions.get(0).asObject(); this.displayName = Utils.getString(object, "displayName"); this.description = Utils.getString(object, "description"); this.developer = Utils.getString(object, "developer"); this.extra = Utils.getString(object, "extra"); this.userTileSmallUrl = Utils.getString(object, "userTileSmallUrl"); this.userTileMediumUrl = Utils.getString(object, "userTileMediumUrl"); this.userTileLargeUrl = Utils.getString(object, "userTileLargeUrl"); this.userTileExtraLargeUrl = Utils.getString(object, "userTileExtraLargeUrl"); this.userTileStaticUrl = Utils.getString(object, "userTileStaticUrl"); this.webpage = Utils.getString(object, "webpage"); this.tos = Utils.getString(object, "tos"); this.privacyStatement = Utils.getString(object, "privacyStatement"); this.isTrusted = object.get("isTrusted").asBoolean(); object.get("capabilities").asArray().iterator().forEachRemaining(value -> this.capabilities.add(value.asString())); object.get("supportedLocales").asArray().iterator().forEachRemaining(value -> this.supportedLocales.add(value.asString())); this.agentType = Utils.getString(object, "agentType"); this.starRating = object.get("starRating").asDouble(); }
private JsonValue findOrCreateJsonObject(JsonValue currentVal, String objKey, Integer aryIdx) { if (objKey != null) { JsonObject jsonObj = currentVal.asObject(); if (jsonObj.get(objKey) == null) { JsonValue obj = Json.object(); jsonObj.add(objKey, obj); return obj; } return jsonObj.get(objKey); } else { // aryIdx != null JsonArray jsonAry = currentVal.asArray(); if (jsonAry.size() <= aryIdx || jsonAry.get(aryIdx).equals(Json.NULL)) { JsonValue obj = Json.object(); assureJsonArraySize(jsonAry, aryIdx); jsonAry.set(aryIdx, obj); return obj; } return jsonAry.get(aryIdx); } }
private void decomposeJSONValue(String name, JsonValue val, Map<String, String> map) { if (val.isObject()) { JsonObject obj = val.asObject(); for (String memberName : obj.names()) { this.decomposeJSONValue(name + "." + memberName, obj.get(memberName), map); } } else if (val.isArray()) { JsonArray arr = val.asArray(); for (int i = 0; i < arr.size(); i++) { this.decomposeJSONValue(name + "[" + i + "]", arr.get(i), map); } } else { map.put(name, val.toString()); } }
RealtimeServerConnection(BoxAPIConnection api) { BoxAPIRequest request = new BoxAPIRequest(api, EVENT_URL.build(api.getBaseURL()), "OPTIONS"); BoxJSONResponse response = (BoxJSONResponse) request.send(); JsonObject jsonObject = JsonObject.readFrom(response.getJSON()); JsonArray entries = jsonObject.get("entries").asArray(); JsonObject firstEntry = entries.get(0).asObject(); this.serverURLString = firstEntry.get("url").asString(); this.retries = Integer.parseInt(firstEntry.get("max_retries").asString()); this.timeout = firstEntry.get("retry_timeout").asInt(); this.api = api; }
JsonObject responseJSON = JsonObject.readFrom(batchResponse.getJSON()); List<BoxAPIResponse> responses = new ArrayList<BoxAPIResponse>(); Iterator<JsonValue> responseIterator = responseJSON.get("responses").asArray().iterator(); while (responseIterator.hasNext()) { JsonObject jsonResponse = responseIterator.next().asObject(); BoxAPIResponse response = null; if (jsonResponse.get("headers") != null) { JsonObject batchResponseHeadersObject = jsonResponse.get("headers").asObject(); for (JsonObject.Member member : batchResponseHeadersObject) { String headerName = member.getName();
private static JsonObject getObject(SkypeImpl skype, String username) throws ConnectionException { JsonArray array = Endpoints.PROFILE_INFO .open(skype) .expect(200, "While getting contact info") .as(JsonArray.class) .post(new JsonObject() .add("usernames", new JsonArray() .add(username) ) ); return array.get(0).asObject(); }
private void addDependencies(JsonObject fraction, FractionDescriptor parent) { fraction.get("fractionDependencies").asArray().forEach(entry -> { JsonObject dependency = entry.asObject(); FractionDescriptor descriptor = getFractionDescriptor(dependency); if (parent != null) { parent.addDependency(descriptor); } addDependencies(dependency, descriptor); }); }
private void updateContactInfo() throws ConnectionException { if (this.skype instanceof FullClient) { JsonObject obj = Endpoints.GET_CONTACT_BY_ID .open(skype, skype.getUsername(), username) .as(JsonObject.class) .expect(200, "While getting contact info") .get(); if (obj.get("contacts").asArray().size() > 0) { JsonObject contact = obj.get("contacts").asArray().get(0).asObject(); update(contact); } else { this.isAuthorized = false; this.isBlocked = false; } } }
public synchronized String[] getWalletPublicAddressesWithUnspentOutputs() throws WalletCallException, IOException, InterruptedException { JsonArray jsonUnspentOutputs = executeCommandAndGetJsonArray("listunspent", "0"); Set<String> addresses = new HashSet<>(); for (int i = 0; i < jsonUnspentOutputs.size(); i++) { JsonObject outp = jsonUnspentOutputs.get(i).asObject(); addresses.add(outp.getString("address", "ERROR!")); } return addresses.toArray(new String[0]); }
/** * Add BoxMetaDataFilter to the JsonArray boxMetadataFilterRequestArray. * @param @param bmf accepts a filter that has templateKey, scope, and filters populated. * @return JsonArray that is formated Json request */ private JsonArray formatBoxMetadataFilterRequest() { JsonArray boxMetadataFilterRequestArray = new JsonArray(); JsonObject boxMetadataFilter = new JsonObject() .add("templateKey", this.metadataFilter.getTemplateKey()) .add("scope", this.metadataFilter.getScope()) .add("filters", this.metadataFilter.getFiltersList()); boxMetadataFilterRequestArray.add(boxMetadataFilter); return boxMetadataFilterRequestArray; }
public synchronized boolean isCompletedOperationSuccessful(String opID) throws WalletCallException, IOException, InterruptedException { JsonArray response = this.executeCommandAndGetJsonArray( "z_getoperationstatus", wrapStringParameter("[\"" + opID + "\"]")); JsonObject jsonStatus = response.get(0).asObject(); String status = jsonStatus.getString("status", "ERROR"); Log.info("Operation " + opID + " status is " + response + "."); if (status.equalsIgnoreCase("success")) { return true; } else if (status.equalsIgnoreCase("error") || status.equalsIgnoreCase("failed")) { return false; } else { throw new WalletCallException("Unexpected final operation status response from wallet: " + response.toString()); } }
public synchronized String getOperationFinalErrorMessage(String opID) throws WalletCallException, IOException, InterruptedException { JsonArray response = this.executeCommandAndGetJsonArray( "z_getoperationstatus", wrapStringParameter("[\"" + opID + "\"]")); JsonObject jsonStatus = response.get(0).asObject(); JsonObject jsonError = jsonStatus.get("error").asObject(); return jsonError.getString("message", "ERROR!"); }
private JsonObject getExchangeDataFromRemoteService() { JsonObject data = new JsonObject(); try { URL u = new URL("https://api.coinmarketcap.com/v1/ticker/zencash"); Reader r = new InputStreamReader(u.openStream(), "UTF-8"); JsonArray ar = Json.parse(r).asArray(); data = ar.get(0).asObject(); } catch (Exception ioe) { Log.warning("Could not obtain ZEN exchange information from coinmarketcap.com due to: {0} {1}", ioe.getClass().getName(), ioe.getMessage()); } return data; } }
public HashSet<String> getPropertyAsStringHashSet(String field) { if (mInternalCache.get(field) != null){ return (HashSet<String>)mInternalCache.get(field); } JsonValue value = getAsJsonValue(field); if (value == null || value.isNull()) { return null; } HashSet<String> strings = new HashSet<String>(value.asArray().size()); for (JsonValue member : value.asArray()){ strings.add(member.asString()); } mInternalCache.put(field, strings); return strings; }