当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray.optInt方法代码示例

本文整理汇总了Java中org.json.JSONArray.optInt方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.optInt方法的具体用法?Java JSONArray.optInt怎么用?Java JSONArray.optInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.json.JSONArray的用法示例。


在下文中一共展示了JSONArray.optInt方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseVersionSpec

import org.json.JSONArray; //导入方法依赖的package包/类
private static int[] parseVersionSpec(JSONArray versionsJSON) {
    // Null signifies no overrides to the min-version as specified by the SDK.
    // An empty array would basically turn off the dialog (i.e no supported versions), so
    // DON'T default to that.
    int[] versionSpec = null;
    if (versionsJSON != null) {
        int numVersions = versionsJSON.length();
        versionSpec = new int[numVersions];
        for (int i = 0; i < numVersions; i++) {
            // See if the version was stored directly as an Integer
            int version = versionsJSON.optInt(i, NativeProtocol.NO_PROTOCOL_AVAILABLE);
            if (version == NativeProtocol.NO_PROTOCOL_AVAILABLE) {
                // If not, then see if it was stored as a string that can be parsed out.
                // If even that fails, then we will leave it as NO_PROTOCOL_AVAILABLE
                String versionString = versionsJSON.optString(i);
                if (!isNullOrEmpty(versionString)) {
                    try {
                        version = Integer.parseInt(versionString);
                    } catch (NumberFormatException nfe) {
                        logd(LOG_TAG, nfe);
                        version = NativeProtocol.NO_PROTOCOL_AVAILABLE;
                    }
                }
            }

            versionSpec[i] = version;
        }
    }

    return versionSpec;
}
 
开发者ID:eviltnan,项目名称:kognitivo,代码行数:32,代码来源:Utility.java

示例2: parseJSONDefinition

import org.json.JSONArray; //导入方法依赖的package包/类
private static Map<Integer, Set<Integer>> parseJSONDefinition(JSONObject definition) {
    JSONArray itemsArray = definition.optJSONArray("items");
    if (itemsArray.length() == 0) {
        return null;
    }

    Map<Integer, Set<Integer>> items = new HashMap<>();
    for (int i = 0; i < itemsArray.length(); i++) {
        JSONObject item = itemsArray.optJSONObject(i);
        if (item == null) {
            continue;
        }
        int code = item.optInt("code");
        if (code == 0) {
            continue;
        }
        Set<Integer> subcodes = null;
        JSONArray subcodesArray = item.optJSONArray("subcodes");
        if (subcodesArray != null && subcodesArray.length() > 0) {
            subcodes = new HashSet<>();
            for (int j = 0; j < subcodesArray.length(); j++) {
                int subCode = subcodesArray.optInt(j);
                if (subCode != 0) {
                    subcodes.add(subCode);
                }
            }
        }
        items.put(code, subcodes);
    }
    return items;
}
 
开发者ID:eviltnan,项目名称:kognitivo,代码行数:32,代码来源:FacebookRequestErrorClassification.java

示例3: arrays

import org.json.JSONArray; //导入方法依赖的package包/类
public static int[] arrays(JSONObject root, String key) {

        JSONArray array = root.optJSONArray(key);
        int size = size(array);
        if (size <= 0) {
            return null;
        }
        a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = array.optInt(i);
        }
        return a;
    }
 
开发者ID:freelifer,项目名称:limitjson,代码行数:14,代码来源:LimitJSONs.java

示例4: parseJSONArray

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * 解析JSONArray 获取数组 例如:["1",2,true,"4"]
 *
 * @param jsonArray 数据源
 * @param array     返回值
 * @return
 */
public static int[] parseJSONArray(JSONArray jsonArray, int[] array) {
    if (jsonArray != null) {
        try {
            array = new int[jsonArray.length()];
            for (int i = 0; i < jsonArray.length(); i++) {
                array[i] = jsonArray.optInt(i);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return array;
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:21,代码来源:JsonUtil.java

示例5: cancel

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * Cancel multiple local notifications.
 *
 * @param ids
 *      Set of local notification IDs
 */
private void cancel (JSONArray ids) {
    for (int i = 0; i < ids.length(); i++) {
        int id = ids.optInt(i, 0);

        Notification notification =
                getNotificationMgr().cancel(id);

        if (notification == null)
            continue;

        fireEvent("cancel", notification);
    }
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:20,代码来源:LocalNotification.java

示例6: clear

import org.json.JSONArray; //导入方法依赖的package包/类
/**
 * Clear multiple local notifications without canceling them.
 *
 * @param ids
 *      Set of local notification IDs
 */
private void clear(JSONArray ids){
    for (int i = 0; i < ids.length(); i++) {
        int id = ids.optInt(i, 0);

        Notification notification =
                getNotificationMgr().clear(id);

        if (notification == null)
            continue;

        fireEvent("clear", notification);
    }
}
 
开发者ID:disit,项目名称:siiMobilityAppKit,代码行数:20,代码来源:LocalNotification.java

示例7: parseItem

import org.json.JSONArray; //导入方法依赖的package包/类
private Gif parseItem(@NonNull JSONObject item) {
    Gif.Builder builder = Gif.Builder.newInstance();
    if (item.has("media")) {
        JSONArray array = item.optJSONArray("media");
        if (array.length() > 0) {
            JSONObject object = array.optJSONObject(0);
            if (object.has("tinygif")) {
                JSONObject gifObject = object.optJSONObject("tinygif");
                String url = gifObject.optString("url");
                String preview = gifObject.optString("preview");

                JSONArray dim = gifObject.optJSONArray("dims");
                int width = 0;
                int height = 0;
                if (dim.length() > 1) {
                    width = dim.optInt(0);
                    height = dim.optInt(1);
                }

                builder.width(width)
                        .height(height)
                        .preview(preview)
                        .url(url);
            }
        }
    }
    if (item.has("title")) {
        String title = item.optString("title");
        builder.title(title);
    }
    return builder.build();
}
 
开发者ID:auv1107,项目名称:TextEmoji,代码行数:33,代码来源:TenorGifRemoteDataSource.java

示例8: initLogger

import org.json.JSONArray; //导入方法依赖的package包/类
private void initLogger(final JSONArray args, final CallbackContext callbackContext) {
    try {
        final String jsFileName = args.optString(0) != null ?
                args.optString(0) : DEFAULT_JS_FILENAME;
        final String lcFileName = args.optString(1) != null ?
                args.optString(1) : DEFAULT_LC_FILENAME;
        this.maxFileSizeInKB = args.optString(2) != null ?
                args.optInt(2) : DEFAULT_MAX_FILESIZE_IN_KB;
        this.filterBy = args.optString(3) == null ?
                null : args.optString(3).split(ARRAY_SEPARATOR);
        this.filterOut = args.optString(4) == null ?
                null : args.optString(4).split(ARRAY_SEPARATOR);
        this.enableCallback = args.optBoolean(5);

        if (jsFileName != null) {
            this.jsFile = new File(this.internalStorage, jsFileName);
            this.jsBak = FileTools.rollFile(this.jsFile, null, LOG_ROLLING_EXTENSION);
            this.jsCon = FileTools.rollFile(this.jsFile, LOG_CON_SUFFIX);

            if (this.jsFileWriter == null) {
                this.jsFileWriter = new JsFileWriter(this.jsFile, this.jsBak,
                        this.cordovaInstance, this.maxFileSizeInKB);
            }
        }

        if (lcFileName != null) {
            this.lcFile = new File(this.internalStorage, lcFileName);
            this.lcBak = FileTools.rollFile(this.lcFile, null, LOG_ROLLING_EXTENSION);
            this.lcCon = FileTools.rollFile(this.lcFile, LOG_CON_SUFFIX);
        }

        this.zipFile = new File(this.internalStorage, DEFAULT_ZIP_FILENAME);
        callbackContext.success();
    } catch (Exception e) {
        callbackContext.error(e.getMessage());
    }
}
 
开发者ID:kolbasa,项目名称:cordova-logcat-filelogger,代码行数:38,代码来源:LogCatPlugin.java

示例9: onCreate

import org.json.JSONArray; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Entity$$CREATOR.create("", false);
    limitJsonTv = (TextView) findViewById(R.id.limitjson_ms);
    try {
        JSONObject root = new JSONObject("");
        root.opt("");
        root.optInt("");
        root.optBoolean("");
        root.optLong("");
        float aa = (float) root.optDouble("");
        root.optString("");

        root.optJSONObject("");
        root.optJSONArray("");
        int[] a;
        if (root.has("arr")) {
            JSONArray array = root.optJSONArray("");
            int size = array.length();
            a = new int[size];
            for (int i = 0; i < size; i++) {
                a[i] = array.optInt(i);
            }
        }


    } catch (JSONException e) {
        e.printStackTrace();
    }

    testLimitJson();

    LinearGraphView tu = (LinearGraphView) findViewById(R.id.line_graphic);

    ArrayList<Double> yList = new ArrayList<Double>();
    yList.add((double) 2.103);
    yList.add(4.05);
    yList.add(6.60);
    yList.add(3.08);
    yList.add(4.32);
    yList.add(2.0);
    yList.add(1115.0);

    ArrayList<String> xRawDatas = new ArrayList<String>();
    xRawDatas.add("05-19");
    xRawDatas.add("05-20");
    xRawDatas.add("05-21");
    xRawDatas.add("05-22");
    xRawDatas.add("05-23");
    xRawDatas.add("05-24");
    xRawDatas.add("05-25");
    xRawDatas.add("05-26");
    tu.setData(yList, xRawDatas, 8, 2);
}
 
开发者ID:freelifer,项目名称:limitjson,代码行数:57,代码来源:MainActivity.java

示例10: getInt

import org.json.JSONArray; //导入方法依赖的package包/类
protected int getInt(JSONArray array, int index) {
    return array.optInt(index);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:4,代码来源:CommonParser.java


注:本文中的org.json.JSONArray.optInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。