Code example for JSONObject

Methods: getInt, has, isNull

0
        writer.endArray();
        writer.endObject();
    } 
     
    static public TopList load(JSONObject obj) throws JSONException {
        int top = obj.has("top") && !obj.isNull("top") ? obj.getInt("top") : 10;
        TopList tl = new TopList(top);
         
        if (obj.has("list") && !obj.isNull("list")) {
            JSONArray a = obj.getJSONArray("list");
             
            tl.load(a);
        } 
        return tl;
    } 
     
    public void load(JSONArray a) throws JSONException {
        int length = a.length();
        for (int i = 0; i < length && _list.size() < _top; i++) {
            _list.add(a.getString(i));
        }