本文整理汇总了Java中org.json.JSONArray.getBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.getBoolean方法的具体用法?Java JSONArray.getBoolean怎么用?Java JSONArray.getBoolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.getBoolean方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBooleanArray
import org.json.JSONArray; //导入方法依赖的package包/类
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;
}
}
示例2: getBooleanArray
import org.json.JSONArray; //导入方法依赖的package包/类
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) {
reportException(e);
return null;
}
}
示例3: execute
import org.json.JSONArray; //导入方法依赖的package包/类
/**
* Executes the request.
*
* @param action The action to execute.
* @param args The exec() arguments.
* @param callback The callback context used when
* calling back into JavaScript.
*
* @return Returning false results in a "MethodNotFound" error.
*
* @throws JSONException
*/
@Override
public boolean execute (String action, JSONArray args,
CallbackContext callback) throws JSONException {
if (action.equalsIgnoreCase("configure")) {
JSONObject settings = args.getJSONObject(0);
boolean update = args.getBoolean(1);
configure(settings, update);
}
else
if (action.equalsIgnoreCase("enable")) {
enableMode();
}
else
if (action.equalsIgnoreCase("disable")) {
disableMode();
}
else {
BackgroundExt.execute(action, cordova, webView);
}
callback.success();
return true;
}
示例4: setDebugMode
import org.json.JSONArray; //导入方法依赖的package包/类
public static void setDebugMode(JSONArray data, CallbackContext callbackContext) {
boolean mode;
try {
mode = data.getBoolean(0);
JPushInterface.setDebugMode(mode);
} catch (JSONException e) {
e.printStackTrace();
}
}
示例5: setStatisticsOpen
import org.json.JSONArray; //导入方法依赖的package包/类
/**
* 决定是否启用统计分析功能。
*/
public static void setStatisticsOpen(JSONArray data, CallbackContext callbackContext) {
try {
isStatisticsOpened = data.getBoolean(0);
} catch (JSONException e) {
e.printStackTrace();
}
}
示例6: getBooleanArray
import org.json.JSONArray; //导入方法依赖的package包/类
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;
}
}
示例7: call
import org.json.JSONArray; //导入方法依赖的package包/类
public String call(WebView webView, String jsonStr) {
if (!TextUtils.isEmpty(jsonStr)) {
try {
JSONObject callJson = new JSONObject(jsonStr);
String methodName = callJson.getString("method");
JSONArray argsTypes = callJson.getJSONArray("types");
JSONArray argsVals = callJson.getJSONArray("args");
String sign = methodName;
int len = argsTypes.length();
Object[] values = new Object[len + 1];
int numIndex = 0;
String currType;
values[0] = webView;
for (int k = 0; k < len; k++) {
currType = argsTypes.optString(k);
if ("string".equals(currType)) {
sign += "_S";
values[k + 1] = argsVals.isNull(k) ? null : argsVals.getString(k);
} else if ("number".equals(currType)) {
sign += "_N";
numIndex = numIndex * 10 + k + 1;
} else if ("boolean".equals(currType)) {
sign += "_B";
values[k + 1] = argsVals.getBoolean(k);
} else if ("object".equals(currType)) {
sign += "_O";
values[k + 1] = argsVals.isNull(k) ? null : argsVals.getJSONObject(k);
} else if ("function".equals(currType)) {
sign += "_F";
values[k + 1] = new JsCallback(webView, mInjectedName, argsVals.getInt(k));
} else {
sign += "_P";
}
}
Method currMethod = mMethodsMap.get(sign);
// 方法匹配失败
if (currMethod == null) {
return getReturn(jsonStr, 500, "not found method(" + sign + ") with valid parameters");
}
// 数字类型细分匹配
if (numIndex > 0) {
Class[] methodTypes = currMethod.getParameterTypes();
int currIndex;
Class currCls;
while (numIndex > 0) {
currIndex = numIndex - numIndex / 10 * 10;
currCls = methodTypes[currIndex];
if (currCls == int.class) {
values[currIndex] = argsVals.getInt(currIndex - 1);
} else if (currCls == long.class) {
// WARN: argsJson.getLong(k + defValue) will return
// a bigger incorrect number
values[currIndex] = Long.parseLong(argsVals.getString(currIndex - 1));
} else {
values[currIndex] = argsVals.getDouble(currIndex - 1);
}
numIndex /= 10;
}
}
return getReturn(jsonStr, 200, currMethod.invoke(null, values));
} catch (Exception e) {
// 优先返回详细的错误信息
if (e.getCause() != null) {
return getReturn(jsonStr, 500, "method execute error:" + e.getCause().getMessage());
}
return getReturn(jsonStr, 500, "method execute error:" + e.getMessage());
}
} else {
return getReturn(jsonStr, 500, "call data empty");
}
}
示例8: call
import org.json.JSONArray; //导入方法依赖的package包/类
public String call(WebView webView, JSONObject jsonObject) {
long time = 0;
if (LogUtils.isDebug()) {
time = android.os.SystemClock.uptimeMillis();
}
if (jsonObject != null) {
try {
String methodName = jsonObject.getString(KEY_METHOD);
JSONArray argsTypes = jsonObject.getJSONArray(KEY_TYPES);
JSONArray argsVals = jsonObject.getJSONArray(KEY_ARGS);
String sign = methodName;
int len = argsTypes.length();
Object[] values = new Object[len];
int numIndex = 0;
String currType;
for (int k = 0; k < len; k++) {
currType = argsTypes.optString(k);
if ("string".equals(currType)) {
sign += "_S";
values[k] = argsVals.isNull(k) ? null : argsVals.getString(k);
} else if ("number".equals(currType)) {
sign += "_N";
numIndex = numIndex * 10 + k + 1;
} else if ("boolean".equals(currType)) {
sign += "_B";
values[k] = argsVals.getBoolean(k);
} else if ("object".equals(currType)) {
sign += "_O";
values[k] = argsVals.isNull(k) ? null : argsVals.getJSONObject(k);
} else if ("function".equals(currType)) {
sign += "_F";
values[k] = new JsCallback(webView, mInterfacedName, argsVals.getInt(k));
} else {
sign += "_P";
}
}
Method currMethod = mMethodsMap.get(sign);
// 方法匹配失败
if (currMethod == null) {
return getReturn(jsonObject, 500, "not found method(" + sign + ") with valid parameters", time);
}
// 数字类型细分匹配
if (numIndex > 0) {
Class[] methodTypes = currMethod.getParameterTypes();
int currIndex;
Class currCls;
while (numIndex > 0) {
currIndex = numIndex - numIndex / 10 * 10 - 1;
currCls = methodTypes[currIndex];
if (currCls == int.class) {
values[currIndex] = argsVals.getInt(currIndex);
} else if (currCls == long.class) {
//WARN: argsJson.getLong(k + defValue) will return a bigger incorrect number
values[currIndex] = Long.parseLong(argsVals.getString(currIndex));
} else {
values[currIndex] = argsVals.getDouble(currIndex);
}
numIndex /= 10;
}
}
return getReturn(jsonObject, 200, currMethod.invoke(mInterfaceObj, values), time);
} catch (Exception e) {
LogUtils.safeCheckCrash(TAG, "call", e);
//优先返回详细的错误信息
if (e.getCause() != null) {
return getReturn(jsonObject, 500, "method execute error:" + e.getCause().getMessage(), time);
}
return getReturn(jsonObject, 500, "method execute error:" + e.getMessage(), time);
}
} else {
return getReturn(jsonObject, 500, "call data empty", time);
}
}