Android通过原生方式解析JSON的注意事项

JSONObject的注意事项

  1. 在解析JSON时,JSONObject可以调用两个方法

    public String getString(String name) throws JSONException {
            throw new RuntimeException("Stub!");
    }
    
    public String optString(String name) {
            throw new RuntimeException("Stub!");
    }
    

    这两个方法实现的功能一样,只是在没有值时,getString() 直接抛出错误(org.json.JSONException),而optString()返回一个空值。

posted @ 2019-09-03 09:27  Android_搬码工  阅读(62)  评论(0)    收藏  举报