亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

JSON中optString和getString方法的區(qū)別

 更新時間:2017年07月07日 15:18:24   投稿:mrr  
optString方法會在對應(yīng)的key中的值不存在的時候返回一個空字符串,但是getString會拋一個JSONException 。下面通過一段代碼給大家介紹JSON中optString和getString方法的區(qū)別,感興趣的朋友一起看看吧

optString方法會在對應(yīng)的key中的值不存在的時候返回一個空字符串,但是getString會拋一個JSONException 。

 /**
   * 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, "");
  }

以上所述是小編給大家介紹的JSON中optString和getString方法的區(qū)別,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論