/** * Returns the <code>int</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>int</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public int getInt(String name, int defaultValue) { JsonValue value = get(name); return value != null ? value.asInt() : defaultValue; }
JsonValue json = new JsonReader().parse(file); JsonValue child = json.child; int id = child.asInt()); child = child.next; int[] ans = child.asIntArray(); child = child.next; String que = child.asString();
@Override public Short read(JsonValue jsonValue) throws Exception { return (short) jsonValue.asInt(); }
@Override public int asInt() { return wrapped.asInt(); }
@Override public Integer read(JsonValue jsonValue) throws Exception { return jsonValue.asInt(); }
@Override protected Short getValue(JsonValue jsonValue) throws Exception { return (short) jsonValue.asInt(); }
@Override protected Integer getValue(JsonValue jsonValue) throws Exception { return jsonValue.asInt(); }
/** * Parse a given JsonValue to an int regardless of whether that value is a String or an int. * * @param value a JsonValue to parse to an int. * @return an int representation of the given value. Can throw a runtime exception (ParseException, UnsupportedOperationException, or NumberFormatException). */ public static long parseJsonValueToInteger(JsonValue value) { try { return value.asInt(); } catch (UnsupportedOperationException e) { String s = value.asString().replace("\"", ""); return Integer.parseInt(s); } }
/** * Returns the <code>int</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>int</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public int getInt(String name, int defaultValue) { JsonValue value = get(name); return value != null ? value.asInt() : defaultValue; }
/** * Returns the <code>int</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>int</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public int getInt(String name, int defaultValue) { JsonValue value = get(name); return value != null ? value.asInt() : defaultValue; }
public Integer getAsInt(final String field){ JsonValue value = getAsJsonValue(field); if (value == null || value.isNull()) { return null; } return value.asInt(); }
/** * Process an object. * @param object The object. * @param targetcl If not null, the traverser should make sure that the result object is compatible with the class loader, * e.g. by cloning the object using the class loaded from the target class loader. * @return The processed object. */ public Object process(Object object, Type type, List<ITraverseProcessor> processors, Traverser traverser, Map<Object, Object> traversed, boolean clone, ClassLoader targetcl, Object context) { JsonObject obj = (JsonObject)object; int rgb = obj.getInt("value", 0); Color ret = new Color(rgb); // traversed.put(object, ret); // ((JsonReadContext)context).addKnownObject(ret); JsonValue idx = (JsonValue)obj.get(JsonTraverser.ID_MARKER); if(idx!=null) ((JsonReadContext)context).addKnownObject(ret, idx.asInt()); return ret; } }
public int getPort() { JsonObject server = json.get("server").asObject(); return server.get("port").asInt(); }
public int getPort() { JsonObject server = json.get("server").asObject(); return server.get("port").asInt(); }
private List<BoxFolder> parsePathCollection(JsonObject jsonObject) { int count = jsonObject.get("total_count").asInt(); List<BoxFolder> pathCollection = new ArrayList<BoxFolder>(count); JsonArray entries = jsonObject.get("entries").asArray(); for (JsonValue value : entries) { JsonObject entry = value.asObject(); BoxFolder folder = new BoxFolder(); folder.createFromJson(entry); pathCollection.add(folder); } return pathCollection; }
/** * Process an object. * @param object The object. * @param targetcl If not null, the traverser should make sure that the result object is compatible with the class loader, * e.g. by cloning the object using the class loaded from the target class loader. * @return The processed object. */ public Object process(Object object, Type type, List<ITraverseProcessor> processors, Traverser traverser, Map<Object, Object> traversed, boolean clone, ClassLoader targetcl, Object context) { JsonObject obj = (JsonObject)object; JsonValue val = obj.get("value"); byte[] vals = (byte[])traverser.traverse(val, byte[].class, processors, targetcl, context); BigInteger ret = new BigInteger(vals); JsonValue idx = (JsonValue)obj.get(JsonTraverser.ID_MARKER); if(idx!=null) ((JsonReadContext)context).addKnownObject(ret, idx.asInt()); return ret; } }
EventLog(BoxAPIConnection api, JsonObject json, String streamPosition, int limit) { this.streamPosition = streamPosition; this.limit = limit; this.nextStreamPosition = json.get("next_stream_position").asString(); this.chunkSize = json.get("chunk_size").asInt(); this.set = new LinkedHashSet<BoxEvent>(this.chunkSize); JsonArray entries = json.get("entries").asArray(); for (JsonValue entry : entries) { this.set.add(new BoxEvent(api, entry.asObject())); } }
private List<BoxFolder.Info> parsePathCollection(JsonObject jsonObject) { int count = jsonObject.get("total_count").asInt(); List<BoxFolder.Info> pathCollection = new ArrayList<BoxFolder.Info>(count); JsonArray entries = jsonObject.get("entries").asArray(); for (JsonValue value : entries) { JsonObject entry = value.asObject(); String id = entry.get("id").asString(); BoxFolder folder = new BoxFolder(getAPI(), id); pathCollection.add(folder.new Info(entry)); } return pathCollection; }
private List<BoxTaskAssignment.Info> parseTaskAssignmentCollection(JsonObject jsonObject) { int count = jsonObject.get("total_count").asInt(); List<BoxTaskAssignment.Info> taskAssignmentCollection = new ArrayList<BoxTaskAssignment.Info>(count); JsonArray entries = jsonObject.get("entries").asArray(); for (JsonValue value : entries) { JsonObject entry = value.asObject(); String id = entry.get("id").asString(); BoxTaskAssignment assignment = new BoxTaskAssignment(getAPI(), id); taskAssignmentCollection.add(assignment.new Info(entry)); } return taskAssignmentCollection; } }
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; }