zoukankan      html  css  js  c++  java
  • org.json.JSONObject的getString和optString使用注意事项

    结论:org.json.JSONObject的getString如果取不到对应的key会抛出异常,optString则不会

    /**
         * Returns the value mapped by {@code name} if it exists, coercing it if
         * necessary, or throws if no such mapping exists.
         *
         * @throws JSONException if no such mapping exists.
         */
        public String getString(String name) throws JSONException {
            Object object = get(name);
            String result = JSON.toString(object);
            if (result == null) {
                throw JSON.typeMismatch(name, object, "String");
            }
            return result;
        }
     
        /**
         * Returns the value mapped by {@code name} if it exists, coercing it if
         * necessary, or the empty string if no such mapping exists.
         */
        public String optString(String name) {
            return optString(name, "");
        }

  • 相关阅读:
    关于System.currentTimeMillis()
    jpa
    java登录密码效验
    Yum 命令语法
    yum 源的配置与使用
    通过yum安装mysql
    centos 验证mysql的安装
    rpm
    GIT 切换到远程分支
    spring mvc 官方下载
  • 原文地址:https://www.cnblogs.com/tc310/p/10718993.html
Copyright © 2011-2022 走看看