Code example for JSONArray

Methods: getJSONArraylength

             * themselves. We are interested in the second and third elements, both of which 
             * should be JSON arrays. The second element/array contains the suggestions and the 
             * third element contains the descriptions. Some search engines don't support 
             * suggestion descriptions so the third element is optional. 
            JSONArray results = new JSONArray(content);
            JSONArray suggestions = results.getJSONArray(1);
            JSONArray descriptions = null;
            if (results.length() > 2) {
                descriptions = results.getJSONArray(2);
                // Some search engines given an empty array "[]" for descriptions instead of 
                // not including it in the response. 
                if (descriptions.length() == 0) {
                    descriptions = null;
            return new SuggestionsCursor(suggestions, descriptions);
        } catch (JSONException e) {
            Log.w(TAG, "Error", e);
Contextual code suggestions in your IDE  Get Codota for Java