Example usage for org.json.simple JSONArray add

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

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:com.bigml.histogram.Gap.java

@Override
@SuppressWarnings("unchecked")
public String toString() {
    JSONArray jsonArray = new JSONArray();
    jsonArray.add(_weight);
    jsonArray.add(_startBin);//from ww  w. jav  a2 s .  c  o  m
    jsonArray.add(_endBin);
    return jsonArray.toJSONString();
}

From source file:bhl.pages.handler.PagesCropRectHandler.java

/**
 * Make a default crop rect when the page doesn't specify one
 * @return a JSONArray//  ww w  .  ja  v a 2 s. c  o m
 */
private JSONArray getDefaultCropRect() {
    JSONArray outer = new JSONArray();
    JSONArray tl = new JSONArray();
    tl.add(0.0);
    tl.add(0.0);
    outer.add(tl);
    JSONArray tr = new JSONArray();
    tr.add(100.0);
    tr.add(0.0);
    outer.add(tr);
    JSONArray br = new JSONArray();
    br.add(100.0);
    br.add(100.0);
    outer.add(br);
    JSONArray bl = new JSONArray();
    bl.add(0.0);
    bl.add(100.0);
    outer.add(bl);
    return outer;
}

From source file:com.piusvelte.hydra.AuthServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    ServletContext servletContext = getServletContext();
    ConnectionManager connMgr = ConnectionManager.getInstance(servletContext);
    JSONObject j = new JSONObject();
    String token = request.getParameter("token");
    if ((token != null) && (token.length() > 0)) {
        try {//from   ww  w .jav a2  s . co  m
            connMgr.authorizeToken(token);
        } catch (Exception e) {
            servletContext.log(e.getMessage());
            JSONArray errors = new JSONArray();
            errors.add(e.getMessage());
            j.put("errors", errors);
            response.setStatus(403);
        }
    } else {
        try {
            j.put("result", connMgr.createToken());
        } catch (Exception e) {
            servletContext.log(e.getMessage());
            JSONArray errors = new JSONArray();
            errors.add(e.getMessage());
            j.put("errors", errors);
            response.setStatus(403);
        }
    }
    response.getWriter().write(j.toJSONString());
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.json.ZonesQuery.java

@SuppressWarnings("unchecked")
public String execute(IServletConfig config, String[] parameters) {

    if (mapper == null) {
        return "";
    }/*from  w  ww .j av  a 2 s .  c om*/

    Set<IZone> zones = mapper.getZones();

    JSONArray a = new JSONArray();
    for (IZone zone : zones) {
        a.add(zone);
    }

    return JSONValue.toJSONString(a);
}

From source file:com.shazam.dataengineering.pipelinebuilder.DeploymentLog.java

public void add(Deployment deployment) {
    JSONArray deployments = (JSONArray) log.get(ROOT);
    deployments.add(deployment.toJSON());
}

From source file:edu.iu.incntre.flowscale.util.JSONConverter.java

/** 
 * convert from status of OFPhysicalPort to JSONArray
 * @param portList/*from   w w  w .  j  a va2s  .co m*/
 * @return JSONArray of an ArrayList<OFPhysicalPort>
 */

public static JSONArray toPortStatus(List<OFPhysicalPort> portList) {

    JSONArray jsonArray = new JSONArray();
    for (OFPhysicalPort pp : portList) {

        JSONObject obj = new JSONObject();
        if (pp.getPortNumber() < 0) {
            continue;
        }
        obj.put("port_id", pp.getPortNumber());
        obj.put("port_address", HexString.toHexString(pp.getHardwareAddress()));
        obj.put("config", pp.getConfig());
        obj.put("supported", pp.getSupportedFeatures());
        obj.put("current", pp.getCurrentFeatures());

        obj.put("state", pp.getState());

        FlowscaleController.logger.debug("port {}", pp.getPortNumber());
        FlowscaleController.logger.debug("h/w {}", HexString.toHexString(pp.getHardwareAddress()));

        FlowscaleController.logger.debug("state {}", pp.getState());

        FlowscaleController.logger.debug("-------");

        jsonArray.add(obj);

    }

    return jsonArray;

}

From source file:com.facebook.tsdb.tsdash.server.data.DataTable.java

@SuppressWarnings("unchecked")
private JSONArray generateColumns() {
    JSONArray cols = new JSONArray();
    cols.add(newColumn("Date", "datetime"));
    for (Metric metric : metrics) {
        for (TagsArray timeSeries : metric.timeSeries.keySet()) {
            cols.add(newColumn(renderLineTitle(metric, timeSeries), "number"));
        }//  ww w.  ja  va  2 s .  co  m
    }
    return cols;
}

From source file:anotadorderelacoes.model.UtilidadesPacotes.java

/**
 * Converte um arquivo de texto puro para o formato JSON aceito pela ARS.
 * O arquivo de texto deve conter uma sentena por linha.
 *
 * @param arquivoTexto Arquivo de texto puro
 * @param arquivoSaida Arquivo de texto convertido para o formato JSON
 *//*w  w  w. jav a 2 s  .  c  om*/
public static void converterTextoJson(File arquivoTexto, File arquivoSaida) {

    BufferedReader br;
    BufferedWriter bw;
    String linha;
    int contadorSentencas = 1;

    try {

        //br = new BufferedReader( new FileReader( arquivoTexto ) );
        br = new BufferedReader(new InputStreamReader(new FileInputStream(arquivoTexto), "UTF-8"));
        //bw = new BufferedWriter( new FileWriter( arquivoSaida ) );
        bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(arquivoSaida), "UTF-8"));

        bw.write("# Arquivo \"" + arquivoTexto.getName() + "\" convertido para o formato JSON\n");
        bw.write("===\n");

        // Uma sentena por linha
        while ((linha = br.readLine()) != null) {

            JSONObject sentenca = new JSONObject();
            JSONArray tokens = new JSONArray();

            sentenca.put("id", contadorSentencas++);
            sentenca.put("texto", linha);
            sentenca.put("comentarios", "");

            sentenca.put("termos", new JSONArray());
            sentenca.put("relacoes", new JSONArray());
            sentenca.put("anotadores", new JSONArray());

            sentenca.put("anotada", false);
            sentenca.put("ignorada", false);

            // Separao simples de tokens
            for (String token : linha.split(" "))
                tokens.add(novoToken(token, token, null, null));
            sentenca.put("tokens", tokens);

            bw.write(sentenca.toString() + "\n");

        }

        bw.close();
        br.close();

        Logger.getLogger("ARS logger").log(Level.INFO, "Arquivo JSON \"{0}\" gravado.",
                arquivoSaida.getAbsolutePath());

    } catch (FileNotFoundException ex) {
        Logger.getLogger("ARS logger").log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger("ARS logger").log(Level.SEVERE, null, ex);
    }

}

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

@Override
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    try {//from   ww  w .  j  a v a  2  s  .com
        TsdbDataProvider dataProvider = TsdbDataProviderFactory.get();
        String[] metrics = dataProvider.getMetrics();
        response.setContentType("text/plain");
        JSONArray encoded = new JSONArray();
        for (String metric : metrics) {
            encoded.add(metric);
        }
        out.println(encoded.toJSONString());
    } catch (Exception e) {
        out.println(getErrorResponse(e));
    }
    out.close();
}

From source file:di.uniba.it.tee2.api.v1.NaturalSearchService.java

@GET
public Response search(@QueryParam("contextQuery") String query, @QueryParam("timeQuery") String timeQuery,
        @QueryParam("n") int n) {
    try {/*w  ww  .  j  a  v a  2  s. c  om*/
        SearchServiceWrapper instance = SearchServiceWrapper.getInstance(
                ServerConfig.getInstance().getProperty("search.language"),
                ServerConfig.getInstance().getProperty("search.index"));
        List<SearchResult> search = instance.getSearch().naturalSearch(query, timeQuery, n);
        JSONObject json = new JSONObject();
        json.put("size", search.size());
        JSONArray results = new JSONArray();
        for (SearchResult sr : search) {
            results.add(sr.toJSON());
        }
        json.put("results", results);
        return Response.ok(json.toString()).build();
    } catch (Exception ex) {
        Logger.getLogger(NaturalSearchService.class.getName()).log(Level.SEVERE, null, ex);
        return Response.serverError().build();
    }
}