Example usage for org.json.simple JSONArray size

List of usage examples for org.json.simple JSONArray size

Introduction

In this page you can find the example usage for org.json.simple JSONArray size.

Prototype

public int size() 

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:com.mp.gw2api.base.GW2APIDataList.java

@Override
public void LoadFromJsonText(String text) {
    JSONParser parser = new JSONParser();
    JSONObject json;/*from  www .ja va  2 s  .  c o m*/
    try {
        //Parse json array
        JSONArray ja = (JSONArray) parser.parse(text);

        //Create object array to retrieve data
        maps = new long[ja.size()];
        if (ja != null) {
            for (int i = 0; i < ja.size(); i++) {
                maps[i] = (long) ja.get(i);
            }
        }

    } catch (ParseException ex) {
        Logger.getLogger(GW2APIDataList.class.getName()).log(Level.SEVERE, null, ex);
        maps = null;
    }

}

From source file:info.usbo.skypetwitter.VK.java

private String findAttachment(JSONObject js) throws ParseException {
    String att = "";
    System.out.println("att0" + js.get("id").toString());
    if (js.get("attachments") != null) {
        System.out.println("att1");
        JSONArray attach = (JSONArray) new JSONParser().parse(js.get("attachments").toString());
        if (attach.size() > 0) {
            System.out.println("att2");
            JSONObject attach1 = (JSONObject) new JSONParser().parse(attach.get(0).toString());
            if (attach1.get("type") != null && "photo".equals(attach1.get("type").toString())) {
                System.out.println("att3");
                JSONObject photo = (JSONObject) new JSONParser().parse(attach1.get("photo").toString());
                if (photo.get("photo_604") != null) {
                    att = photo.get("photo_604").toString();
                }/*from w  w  w.  j  a  va  2s . c  o  m*/
            }
        }
    }
    return att;
}

From source file:bolt.DucksBoardMap.java

public DucksBoardMap(String json) {
    Object obj = JSONValue.parse(json);
    JSONArray array = (JSONArray) obj;/*from   w ww  .  j  av  a2  s .com*/
    JSONObject obj2 = (JSONObject) array.get(0);
    this.idString = obj2.get("id").toString();
    this.keyString = obj2.get("key").toString();
    JSONArray fieldsJson = (JSONArray) obj2.get("requiredFields");
    String[] fieldsTmp = new String[fieldsJson.size()];
    //if (fieldsJson.size() == 0) 
    for (int i = 0; i < fieldsJson.size(); i++) {
        fieldsTmp[i] = (String) fieldsJson.get(i);
    }

    this.fields = fieldsTmp;

}

From source file:info.usbo.skypetwitter.VK.java

VK(String line) throws ParseException {
    JSONObject json2 = (JSONObject) new JSONParser().parse(line);
    id = Long.parseLong(json2.get("id").toString());
    text = json2.get("text").toString();
    if ("".equals(text)) {
        if (json2.get("copy_history") != null) {
            JSONArray json3 = (JSONArray) new JSONParser().parse(json2.get("copy_history").toString());
            if (json3.size() > 0) {
                JSONObject json4 = (JSONObject) new JSONParser().parse(json3.get(0).toString());
                text = json4.get("text").toString();
            }//from   www  . j a  va 2 s  . co  m
        } else {
            text = "";
        }
    }
    date = new Date(Long.parseLong(json2.get("date").toString()) * 1000);
    attachment = findAttachment(json2);
}

From source file:bolt.DucksBoardTimeline.java

public DucksBoardTimeline(String json) {
    Object obj = JSONValue.parse(json);
    JSONArray array = (JSONArray) obj;/*  w w  w. ja v  a 2  s.  c o  m*/
    JSONObject obj2 = (JSONObject) array.get(0);
    this.idString = obj2.get("id").toString();
    this.keyString = obj2.get("key").toString();
    JSONArray fieldsJson = (JSONArray) obj2.get("requiredFields");
    String[] fieldsTmp = new String[fieldsJson.size()];
    //if (fieldsJson.size() == 0) 
    for (int i = 0; i < fieldsJson.size(); i++) {
        fieldsTmp[i] = (String) fieldsJson.get(i);
    }

    this.fields = fieldsTmp;

}

From source file:com.intuit.tweetstest.TweetsController.java

public List<String> getFollowingList(JSONArray jsonArray) {
    List<String> followingList = null;
    int length = jsonArray.size();
    if (jsonArray != null) {
        followingList = new ArrayList<>();
        for (int i = 0; i < length; i++) {
            followingList.add((String) jsonArray.get(i));
        }//  w  w w  .j av a 2  s  .  co  m
    }
    return followingList;
}

From source file:model.SearchResponse.java

@Override
public void load(JSONObject object) {
    Iterator it = object.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, Object> pair = (Map.Entry) it.next();
        String key = pair.getKey();
        Object value = pair.getValue();

        if (value == null) {
            continue;
        }/*www .j a va2 s.c  om*/

        switch (key) {
        case "used_indices":
            this.used_indices = new Index();
            JSONArray usedIndices = (JSONArray) value;
            if (usedIndices.size() == 1) {
                this.used_indices.load((JSONObject) usedIndices.get(0));
            }
            break;
        case "messages":
            this.loadMessage((JSONArray) value);
            break;
        default:
            this.setAttribute(key, value.toString());
        }
    }
    System.out.println(this);
}

From source file:kr.co.bitnine.octopus.testutils.MemoryDatabaseTest.java

private void verifyTableEquals(JSONObject expectedTable, ResultSet actualRows) throws Exception {
    ResultSetMetaData actualRowsMetaData = actualRows.getMetaData();

    JSONArray expectedSchema = (JSONArray) expectedTable.get("table-schema");
    assertEquals(expectedSchema.size(), actualRowsMetaData.getColumnCount());
    for (int i = 0; i < expectedSchema.size(); i++)
        assertEquals(expectedSchema.get(i), actualRowsMetaData.getColumnName(i + 1));

    for (Object rowObj : (JSONArray) expectedTable.get("table-rows")) {
        JSONArray row = (JSONArray) rowObj;
        actualRows.next();/*from w  w w .  jav  a  2 s. c  o m*/

        for (int i = 0; i < row.size(); i++) {
            Object expected = row.get(i);
            Object actual;

            int sqlType = actualRowsMetaData.getColumnType(i + 1);
            switch (sqlType) {
            case Types.INTEGER:
                if (expected instanceof Boolean)
                    expected = (long) ((Boolean) expected ? 1 : 0);
                actual = actualRows.getLong(i + 1);
                break;
            case Types.NULL:
            case Types.FLOAT:
            case Types.VARCHAR:
                actual = actualRows.getObject(i + 1);
                break;
            default:
                throw new RuntimeException("java.sql.Types " + sqlType + " is not supported");
            }

            assertEquals(expected, actual);
        }
    }
    assertFalse(actualRows.next());
}

From source file:com.facebook.tsdb.tsdash.server.DataEndpoint.java

@Override
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    try {//www.jav a  2  s  . c om
        long ts = System.currentTimeMillis();
        // decode parameters
        String jsonParams = request.getParameter("params");
        if (jsonParams == null) {
            throw new Exception("Parameters not specified");
        }
        JSONObject jsonParamsObj = (JSONObject) JSONValue.parse(jsonParams);
        long tsFrom = (Long) jsonParamsObj.get("tsFrom");
        long tsTo = (Long) jsonParamsObj.get("tsTo");
        JSONArray metricsArray = (JSONArray) jsonParamsObj.get("metrics");
        if (metricsArray.size() == 0) {
            throw new Exception("No metrics to fetch");
        }
        MetricQuery[] metricQueries = new MetricQuery[metricsArray.size()];
        for (int i = 0; i < metricsArray.size(); i++) {
            metricQueries[i] = MetricQuery.fromJSONObject((JSONObject) metricsArray.get(i));
        }

        TsdbDataProvider dataProvider = TsdbDataProviderFactory.get();
        Metric[] metrics = new Metric[metricQueries.length];
        for (int i = 0; i < metrics.length; i++) {
            MetricQuery q = metricQueries[i];
            metrics[i] = dataProvider.fetchMetric(q.name, tsFrom, tsTo, q.tags, q.orders);
            metrics[i] = metrics[i].dissolveTags(q.getDissolveList(), q.aggregator);
            if (q.rate) {
                metrics[i].computeRate();
            }
        }
        long loadTime = System.currentTimeMillis() - ts;
        JSONObject responseObj = new JSONObject();
        JSONArray encodedMetrics = new JSONArray();
        for (Metric metric : metrics) {
            encodedMetrics.add(metric.toJSONObject());
        }
        responseObj.put("metrics", encodedMetrics);
        responseObj.put("loadtime", loadTime);
        DataTable dataTable = new DataTable(metrics);
        responseObj.put("datatable", dataTable.toJSONObject());
        out.println(responseObj.toJSONString());
        long encodingTime = System.currentTimeMillis() - ts - loadTime;
        logger.info("[Data] time frame: " + (tsTo - tsFrom) + "s, " + "load time: " + loadTime + "ms, "
                + "encoding time: " + encodingTime + "ms");
    } catch (Exception e) {
        out.println(getErrorResponse(e));
    }
    out.close();
}

From source file:JSONParser.JSONToHTMLRenderer.java

private String renderContentRows(JSONArray content, String[] rowHeader) {
    String renderedRows = "";

    if (content == null || content.size() == 0) {

        renderedRows = "<tr >\n" + "<td colspan=\"" + rowHeader.length
                + "\"><center style=\"color: rgb(255, 0, 0);\">" + "No pending tickets available"
                + "</center></td></tr> \n";
        return renderedRows;
    } else {/*from  w w  w  .j  av a  2 s.  c  om*/

        for (Iterator rowItr = content.iterator(); rowItr.hasNext();) {
            JSONObject WOERow = (JSONObject) rowItr.next();
            String colorCode = (String) WOERow.get("colourCode");
            if (colorCode == null) {
                colorCode = "rgb(0,0,0)";
            }
            renderedRows += "<tr style=\"color: " + colorCode + ";font-weight:bold\">\n";
            for (String columnStr : rowHeader) {
                renderedRows += "<td valign=\"top\" ><b>" + WOERow.get(columnStr) + "</b></td>\n";
            }

            renderedRows += "</tr>";
        }
        return renderedRows;
    }

}