Example usage for twitter4j JSONArray length

List of usage examples for twitter4j JSONArray length

Introduction

In this page you can find the example usage for twitter4j JSONArray length.

Prototype

public int length() 

Source Link

Usage

From source file:org.csi.yucca.storage.datamanagementapi.service.StoreService.java

protected static String formatMessages(Locale locale, String element) {

    JSONObject messages = loadMessages(locale, element);

    log.debug("[StoreService::formatMessages] - START");
    StringBuffer sb = new StringBuffer("");
    String loc = locale.getLanguage().substring(0, 1).toUpperCase() + locale.getLanguage().substring(1);

    String label1 = (element.equals("tags") ? "streamTags" : "streamDomains");
    String label2 = (element.equals("tags") ? "tagCode" : "codDomain");

    try {//from   www. ja  va 2s.  c  om
        JSONObject streamTags = messages.getJSONObject(label1);
        JSONArray elements = streamTags.getJSONArray("element");
        for (int i = 0; i < elements.length(); i++) {
            String tagCode = elements.getJSONObject(i).getString(label2);
            String langEl = elements.getJSONObject(i).getString("lang" + loc);
            sb.append(tagCode + " = " + langEl + "\n");
        }

    } catch (JSONException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
    } finally {
        log.debug("[StoreService::formatMessages] - END");
    }
    return sb.toString();
}