Example usage for twitter4j JSONArray getJSONObject

List of usage examples for twitter4j JSONArray getJSONObject

Introduction

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

Prototype

public JSONObject getJSONObject(int index) throws JSONException 

Source Link

Document

Returns the value at index if it exists and is a JSONObject .

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  w w w. j a va 2s .c o  m
        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();
}