本文整理了Java中org.codehaus.jettison.json.JSONArray.getInt()
方法的一些代码示例,展示了JSONArray.getInt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONArray.getInt()
方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONArray
类名称:JSONArray
方法名:getInt
[英]Get the int value associated with an index.
[中]获取与索引关联的int值。
代码示例来源:origin: org.codehaus.jettison/jettison
/**
* Get the optional int value associated with an index.
* The defaultValue is returned if there is no value for the index,
* or if the value is not a number and cannot be converted to a number.
* @param index The index must be between 0 and length() - 1.
* @param defaultValue The default value.
* @return The value.
*/
public int optInt(int index, int defaultValue) {
try {
return getInt(index);
} catch (Exception e) {
return defaultValue;
}
}
代码示例来源:origin: org.codehaus.jettison/com.springsource.org.codehaus.jettison
/**
* Get the optional int value associated with an index.
* The defaultValue is returned if there is no value for the index,
* or if the value is not a number and cannot be converted to a number.
* @param index The index must be between 0 and length() - 1.
* @param defaultValue The default value.
* @return The value.
*/
public int optInt(int index, int defaultValue) {
try {
return getInt(index);
} catch (Exception e) {
return defaultValue;
}
}
代码示例来源:origin: org.apache.apex/malhar-library
@Override
public void setFieldFromJSON(GPOMutable gpo, String field, JSONArray jo, int index)
{
int val;
try {
val = jo.getInt(index);
} catch (JSONException ex) {
throw new IllegalArgumentException("The key " + field + " does not have a valid int value.", ex);
}
gpo.setField(field, val);
}
代码示例来源:origin: org.apache.apex/malhar-library
@Override
public void setFieldFromJSON(GPOMutable gpo, String field, JSONArray jo, int index)
{
int val;
try {
val = jo.getInt(index);
} catch (JSONException ex) {
throw new IllegalArgumentException("The key " + field + " does not have a valid short value.", ex);
}
if (val < (int)Short.MIN_VALUE) {
throw new IllegalArgumentException("The key " + field + " has a value " + val
+ " which is too small to fit into a short.");
}
if (val > (int)Short.MAX_VALUE) {
throw new IllegalArgumentException("The key " + field + " has a value " + val
+ " which is too large to fit into a short.");
}
gpo.setField(field, (short)val);
}
代码示例来源:origin: org.apache.apex/malhar-library
@Override
public void setFieldFromJSON(GPOMutable gpo, String field, JSONArray jo, int index)
{
int val;
try {
val = jo.getInt(index);
} catch (JSONException ex) {
throw new IllegalArgumentException("The key " + field + " does not have a valid byte value.", ex);
}
if (val < (int)Byte.MIN_VALUE) {
throw new IllegalArgumentException("The key " + field + " has a value " + val
+ " which is too small to fit into a byte.");
}
if (val > (int)Byte.MAX_VALUE) {
throw new IllegalArgumentException("The key " + field + " has a value " + val
+ " which is too larg to fit into a byte.");
}
gpo.setField(field, (byte)val);
}
代码示例来源:origin: org.apache.apex/malhar-library
intVal = ja.getInt(index);
} catch (JSONException ex) {
throw new IllegalArgumentException("The index " + index + " does not have a valid " + type + " value.", ex);
代码示例来源:origin: com.couchbase.client/couchbase-client
short master = (short) rows.getInt(0);
int replicaSize = rows.length() - 1;
short[] replicas = new short[replicaSize];
for (int j = 1; j < rows.length(); j++) {
replicas[j - 1] = (short) rows.getInt(j);
代码示例来源:origin: usc-cloud/goffish
@Override
public IntCollection getMatchingPartitions(String graphId, URI locationToMatch) {
if (graphId == null) {
throw new IllegalArgumentException();
}
if (locationToMatch == null) {
throw new IllegalArgumentException();
}
WebResource r = _baseResource.path(NameNodeServer.DIRECTORY).path(graphId).queryParam(NameNodeServer.GET_GRAPH_PARTITIONS_LOCATIONTOMATCH_QP, locationToMatch.toString());
ClientResponse response = r.get(ClientResponse.class);
Status status = response.getClientResponseStatus();
if (Status.OK.equals(status)) {
JSONArray array = response.getEntity(JSONArray.class);
IntArrayList partitions = new IntArrayList(array.length());
try {
for (int i = 0; i < array.length(); i++) {
partitions.add(array.getInt(i));
}
} catch (JSONException e) {
throw new IllegalStateException(e);
}
return partitions;
} else if (Status.NOT_FOUND.equals(status)) {
return null;
} else if (Status.BAD_REQUEST.equals(status)) {
throw new IllegalArgumentException(response.getEntity(String.class));
}
throw new RuntimeException(status.toString());
}
代码示例来源:origin: usc-cloud/goffish
@Override
public IntCollection getPartitions(String graphId) {
if (graphId == null) {
throw new IllegalArgumentException();
}
WebResource r = _baseResource.path(NameNodeServer.DIRECTORY).path(graphId);
ClientResponse response = r.get(ClientResponse.class);
Status status = response.getClientResponseStatus();
if (Status.OK.equals(status)) {
JSONArray array = response.getEntity(JSONArray.class);
IntArrayList partitions = new IntArrayList(array.length());
try {
for (int i = 0; i < array.length(); i++) {
partitions.add(array.getInt(i));
}
} catch (JSONException e) {
throw new IllegalStateException(e);
}
return partitions;
} else if (Status.NOT_FOUND.equals(status)) {
return null;
} else if (Status.BAD_REQUEST.equals(status)) {
throw new IllegalArgumentException(response.getEntity(String.class));
}
throw new RuntimeException(status.toString());
}
代码示例来源:origin: ORCID/ORCID-Source
JSONArray dateArray = dateParts.getJSONArray(0);
publicationDate.setYear(new Year(dateArray.getInt(0)));
publicationDate.setMonth(new Month(dateArray.getInt(1)));
publicationDate.setDay(new Day(dateArray.getInt(2)));
} catch (JSONException e) {
int day = 0;
if (date.length() > 0 && !JSONObject.NULL.equals(date.get(0))) {
year = date.getInt(0);
month = date.getInt(1);
day = date.getInt(2);
代码示例来源:origin: eclipse-ee4j/glassfish
private boolean sameScalar(ScalarValue want, JSONArray parent, int index) throws Exception {
trace("comparing array scalar element " + index);
String regexp = want.getRegexp();
if (want instanceof StringValue) {
return sameString(((StringValue) want).getValue(), regexp, parent.getString(index));
}
if (want instanceof LongValue) {
return sameString(longToString(((LongValue) want).getValue()), regexp, longToString(parent.getLong(index)));
}
if (want instanceof IntValue) {
return sameString(intToString(((IntValue) want).getValue()), regexp, intToString(parent.getInt(index)));
}
if (want instanceof DoubleValue) {
return sameString(doubleToString(((DoubleValue) want).getValue()), regexp, doubleToString(parent.getDouble(index)));
}
if (want instanceof BooleanValue) {
return sameString(booleanToString(((BooleanValue) want).getValue()), regexp, booleanToString(parent.getBoolean(index)));
}
throw new AssertionError(want + " is not a valid scalar type. Valid types are string, long, int, double, boolean");
}
代码示例来源:origin: inchaincodes/inchain
count = 1;
}else {
count = params.getInt(0);
try {
if(params.length() == 1) {
limit = params.getInt(0);
}else if(params.length() == 2) {
limit = params.getInt(0);
try {
confirm = params.getInt(1);
}catch (Exception e) {
address = params.getString(1);
limit = params.getInt(0);
confirm = params.getInt(1);
address = params.getString(2);
内容来源于网络,如有侵权,请联系作者删除!