當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONArray.getBoolean方法代碼示例

本文整理匯總了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;
	}
}
 
開發者ID:G2159687,項目名稱:ESPD,代碼行數:14,代碼來源:Bundle.java

示例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;
	}
}
 
開發者ID:mango-tree,項目名稱:UNIST-pixel-dungeon,代碼行數:15,代碼來源:Bundle.java

示例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;
}
 
開發者ID:SUTFutureCoder,項目名稱:localcloud_fe,代碼行數:39,代碼來源:BackgroundMode.java

示例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();
  }
}
 
開發者ID:pengkobe,項目名稱:nxtpush-cordova-plugin,代碼行數:10,代碼來源:JPushUtil.java

示例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();
  }
}
 
開發者ID:pengkobe,項目名稱:nxtpush-cordova-plugin,代碼行數:11,代碼來源:JPushUtil.java

示例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;
	}
}
 
開發者ID:kurtyu,項目名稱:PixelDungeonTC,代碼行數:14,代碼來源:Bundle.java

示例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");
	}
}
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:77,代碼來源:JsCallJava.java

示例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);
    }
}
 
開發者ID:Justson,項目名稱:AgentWeb,代碼行數:78,代碼來源:JsCallJava.java


注:本文中的org.json.JSONArray.getBoolean方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。