1、JSONObject 对象中两个方法比较getJSONArray(String key) 和optJSONArray()
public JSONArray getJSONArray(String key) {
this.verifyIsNull();
Object o = this.get(key);
//此处有一个判断null的操作,如果o为null会报错
if (o != null && o instanceof JSONArray) {
return (JSONArray)o;
} else {
throw new JSONException("JSONObject[" + JSONUtils.quote(key) + "] is not a JSONArray.");
}
}
public JSONArray optJSONArray(String key) {
this.verifyIsNull();
Object o = this.opt(key);
return o instanceof JSONArray ? (JSONArray)o : null;
}