本文整理了Java中org.json.JSONArray.getBoolean()
方法的一些代码示例,展示了JSONArray.getBoolean()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONArray.getBoolean()
方法的具体详情如下:
包路径:org.json.JSONArray
类名称:JSONArray
方法名:getBoolean
[英]Returns the value at index if it exists and is a boolean or can be coerced to a boolean.
[中]返回索引处的值(如果该值存在且为布尔值或可以强制为布尔值)。
代码示例来源:origin: zzz40500/GsonFormat
/**
* Get the optional boolean value associated with an index. It returns the
* defaultValue if there is no value at that index or if it is not a Boolean
* or the String "true" or "false" (case insensitive).
*
* @param index
* The index must be between 0 and length() - 1.
* @param defaultValue
* A boolean default.
* @return The truth.
*/
public boolean optBoolean(int index, boolean defaultValue) {
try {
return this.getBoolean(index);
} catch (Exception e) {
return defaultValue;
}
}
代码示例来源:origin: loklak/loklak_server
/**
* Get the optional boolean value associated with an index. It returns the
* defaultValue if there is no value at that index or if it is not a Boolean
* or the String "true" or "false" (case insensitive).
*
* @param index
* The index must be between 0 and length() - 1.
* @param defaultValue
* A boolean default.
* @return The truth.
*/
public boolean optBoolean(int index, boolean defaultValue) {
try {
return this.getBoolean(index);
} catch (Exception e) {
return defaultValue;
}
}
代码示例来源:origin: facebook/facebook-android-sdk
boolean[] array = new boolean[jsonArray.length()];
for (int i = 0; i < array.length; i++) {
array[i] = jsonArray.getBoolean(i);
代码示例来源:origin: Justson/AgentWeb
} else if ("boolean".equals(currType)) {
sign += "_B";
values[k] = argsVals.getBoolean(k);
} else if ("object".equals(currType)) {
sign += "_O";
代码示例来源:origin: googleapis/google-cloud-java
private void assertArray(List<?> actualValues, JSONArray expectedList) throws Exception {
assertThat(actualValues.size()).isEqualTo(expectedList.length());
for (int i = 0; i < actualValues.size(); i++) {
Object actualValue = actualValues.get(i);
if (actualValue == null) {
assertThat(expectedList.isNull(i)).isTrue();
} else {
if (actualValue instanceof Boolean) {
assertThat((Boolean) actualValue).isEqualTo(expectedList.getBoolean(i));
} else if (actualValue instanceof String) {
assertThat((String) actualValue).isEqualTo(expectedList.getString(i));
} else if (actualValue instanceof Long) {
assertThat((Long) actualValue).isEqualTo(expectedList.getLong(i));
} else if (actualValue instanceof Double) {
assertThat((Double) actualValue).isEqualTo(expectedList.getDouble(i));
} else if (actualValue instanceof ByteArray) {
assertThat((ByteArray) actualValue)
.isEqualTo(ByteArray.fromBase64(expectedList.getString(i)));
} else if (actualValue instanceof Struct) {
Struct actualStruct = (Struct) actualValue;
JSONArray expectedFields = expectedList.getJSONArray(i);
assertRow(actualStruct, expectedFields);
}
}
}
}
}
代码示例来源:origin: b3log/latke
/**
* Get the optional boolean value associated with an index. It returns the
* defaultValue if there is no value at that index or if it is not a Boolean
* or the String "true" or "false" (case insensitive).
*
* @param index
* The index must be between 0 and length() - 1.
* @param defaultValue
* A boolean default.
* @return The truth.
*/
public boolean optBoolean(int index, boolean defaultValue) {
try {
return this.getBoolean(index);
} catch (Exception e) {
return defaultValue;
}
}
代码示例来源:origin: googleapis/google-cloud-java
private void assertRow(Struct actualRow, JSONArray expectedRow) throws Exception {
assertThat(actualRow.getColumnCount()).isEqualTo(expectedRow.length());
for (int i = 0; i < expectedRow.length(); i++) {
switch (actualRow.getColumnType(i).getCode()) {
case BOOL:
assertThat(actualRow.getBoolean(i)).isEqualTo(expectedRow.getBoolean(i));
break;
case STRING:
assertThat(actualRow.getString(i)).isEqualTo(expectedRow.getString(i));
break;
case INT64:
assertThat(actualRow.getLong(i)).isEqualTo(expectedRow.getLong(i));
break;
case FLOAT64:
assertThat(actualRow.getDouble(i)).isEqualTo(expectedRow.getDouble(i));
break;
case BYTES:
assertThat(actualRow.getBytes(i))
.isEqualTo(ByteArray.fromBase64(expectedRow.getString(i)));
break;
case ARRAY:
Type elementType = actualRow.getColumnType(i).getArrayElementType();
assertArray(getRawList(actualRow, i, elementType), expectedRow.getJSONArray(i));
break;
default:
Assert.fail("Unexpected type code:" + actualRow.getColumnType(i).getCode());
}
}
}
代码示例来源:origin: rchodava/datamill
@Override
public boolean asBoolean() {
return array.getBoolean(index);
}
代码示例来源:origin: liferay/liferay-mobile-sdk
@Override
public Boolean inBackground(JSONArray jsonArray) throws Exception {
return jsonArray.getBoolean(0);
}
代码示例来源:origin: unchartedsoftware/aperture-tiles
public boolean getAsBoolean () throws JSONException {
if (null != _parentNode) {
return _parentNode.getBoolean(_childNodeName);
} else {
return _parentArray.getBoolean(_index);
}
}
代码示例来源:origin: ConsideredHamster/YetAnotherPixelDungeon
public boolean[] getBooleanArray( String key ) {
try {
JSONArray array = data.getJSONArray( key );
int length = array.length();
boolean[] result = new boolean[length];
for (int i=0; i < length; i++) {
result[i] = array.getBoolean( i );
}
return result;
} catch (JSONException e) {
return null;
}
}
代码示例来源:origin: com.senseidb/sensei-core
/**
* @param jsonValues
* @return
* @throws JSONException
*/
private static boolean[] convertJSONToBoolArray(JSONArray jsonArray) throws JSONException {
boolean[] boolArray = new boolean[jsonArray.length()];
if (jsonArray != null && jsonArray.length() > 0) {
for (int i = 0; i < jsonArray.length(); i++) {
boolArray[i] = jsonArray.getBoolean(i);
}
}
return boolArray;
}
代码示例来源:origin: stackoverflow.com
try {
JSONObject jsonObject = new JSONObject(yourJson);
JSONArray jsonArray = jsonObject.getJSONArray("msg_data");
for(int i=0;i<jsonArray.length();i++) {
if (jsonArray.get(i) instanceof JSONObject) {
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
} else {
Boolean b = jsonArray.getBoolean(i);
}
}
}catch (Exception e) {
e.printStackTrace();
}
代码示例来源:origin: 00-Evan/shattered-pixel-dungeon
public boolean[] getBooleanArray( String key ) {
try {
JSONArray array = data.getJSONArray( key );
int length = array.length();
boolean[] result = new boolean[length];
for (int i=0; i < length; i++) {
result[i] = array.getBoolean( i );
}
return result;
} catch (JSONException e) {
Game.reportException(e);
return null;
}
}
代码示例来源:origin: liferay/liferay-mobile-sdk
public Boolean testHasClassName() throws Exception {
JSONObject _command = new JSONObject();
try {
JSONObject _params = new JSONObject();
_command.put("/portal/test-has-class-name", _params);
}
catch (JSONException _je) {
throw new Exception(_je);
}
JSONArray _result = session.invoke(_command);
if (_result == null) {
return null;
}
return _result.getBoolean(0);
}
代码示例来源:origin: 00-Evan/shattered-pixel-dungeon-gdx
public boolean[] getBooleanArray( String key ) {
try {
JSONArray array = data.getJSONArray( key );
int length = array.length();
boolean[] result = new boolean[length];
for (int i=0; i < length; i++) {
result[i] = array.getBoolean( i );
}
return result;
} catch (JSONException e) {
Game.reportException(e);
return null;
}
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
public static JSONObject deleteHelper(JSONObject params) throws Exception {
if(!params.has("ids")) {
throw new Exception("No 'ids' field provided!");
}
boolean children = false;
if(params.has("children")) {
children = params.getJSONArray("children").getBoolean(0);
}
return deleteHelper(Utils.toSet(params.getJSONArray("ids")), children);
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
public static JSONObject cancelHelper(JSONObject params) throws Exception {
if(!params.has("ids")) {
throw new Exception("No 'ids' field provided!");
}
boolean children = false;
if(params.has("children")) {
children = params.getJSONArray("children").getBoolean(0);
}
return cancelHelper(Utils.toSet(params.getJSONArray("ids")), children);
}
代码示例来源:origin: NationalSecurityAgency/lemongrenade
public static void addChildIDs(JSONObject params) throws Exception {
boolean children = true;
if(params.has("children")) {
children = params.getJSONArray("children").getBoolean(0);
}
if(children && params.has("ids") && params.getJSONArray("ids").length() > 0) {
JSONArray ids = params.getJSONArray("ids");
Set<String> childIDs = getChildIDs(ids);
childIDs.addAll(Utils.toSet(ids));
params.put("ids", Utils.toJson(childIDs));
}
}
代码示例来源:origin: DeviceConnect/DeviceConnect-Android
@Override
public DConnectDataSpec parseJson(final JSONObject json) throws JSONException {
BooleanDataSpec.Builder builder = new BooleanDataSpec.Builder();
if (json.has(KEY_ENUM)) {
JSONArray array = json.getJSONArray(KEY_ENUM);
Boolean[] enumList = new Boolean[array.length()];
for (int i = 0; i < array.length(); i++) {
enumList[i] = array.getBoolean(i);
}
builder.setEnum(enumList);
}
return builder.build();
}
}
内容来源于网络,如有侵权,请联系作者删除!