Example usage for org.json.simple JSONObject toString

List of usage examples for org.json.simple JSONObject toString

Introduction

In this page you can find the example usage for org.json.simple JSONObject toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:LicenseKeyAPI.java

/**
 * Registers the application with the server
 *
 * @param   licenseKey  The license key to register with the server.
 * @param   appID       The application ID to register with the server.
 * @param   userEmail   The users email to register the app with the server.
 * @return              The status code returned from the server.
 **//*from   w ww. j a v a2  s  .  c o  m*/
public int registerApp(String licenseKey, String appID, String userEmail) {
    String URLpostFixEndpoint = "api/client/register_application";

    // Creates HTTP POST request
    HttpPost httppost = new HttpPost(baseServerURLAddress + URLpostFixEndpoint);
    httppost.addHeader("Content-Type", "application/json");
    httppost.setHeader("Content-Type", "application/json; charset= utf-8");
    httppost.setHeader("Accept", "application/json");

    JSONObject json = new JSONObject();
    json.put("email", userEmail);
    json.put("licensekey", licenseKey);
    json.put("appID", appID);

    StringEntity entity = new StringEntity(json.toString(), "utf-8");

    // Adds the POST params to the request
    httppost.setEntity(entity);

    return sendPOST(httppost);
}

From source file:LicenseKeyAPI.java

/**
 * Checks the license status with the server.
 *
 * @param   licenseKey  The license key to verify with the server.
 * @param   appID       The appID to verify with the server.
 * @param   userName    The users name to verify with the server.
 * @return              The status code returned from the server.
 **///from w w  w . j  a  v a  2  s .co m
public int checkApp(String licenseKey, String appID, String userEmail) {
    String URLpostFixEndpoint = "api/client/check_license";

    // Creates HTTP POST request
    HttpPost httppost = new HttpPost(baseServerURLAddress + URLpostFixEndpoint);
    httppost.addHeader("Content-Type", "application/json");
    httppost.setHeader("Content-Type", "application/json; charset= utf-8");
    httppost.setHeader("Accept", "application/json");

    JSONObject json = new JSONObject();
    json.put("email", userEmail);
    json.put("licensekey", licenseKey);
    json.put("appID", appID);

    StringEntity entity = new StringEntity(json.toString(), "utf-8");

    // Adds the POST params to the request
    httppost.setEntity(entity);

    return sendPOST(httppost);
}

From source file:gwap.rest.User.java

@GET
@Path("/{id:[A-Za-z0-9][A-Za-z0-9]*}")
public Response getUser(@PathParam("id") String deviceId) {
    Query query = entityManager.createNamedQuery("person.byDeviceId");
    query.setParameter("deviceId", deviceId);
    Person person = (Person) query.getSingleResult();

    JSONObject userObject = getUserStatistics(deviceId, person);

    return Response.ok(userObject.toString(), MediaType.APPLICATION_JSON).build();
}

From source file:bigtweet.BTSimBatch.java

/**
 * Read a input batch file with set of experiments (one line for parameters
 * configuration) and execute them The file is generated with R
 *//*ww w  .j a v  a 2 s. c  o  m*/
public void runBatchExperiments() {

    generateSeeds();
    generateExperimentResultsObjects();
    loadBatchInputFile();
    loadBatchOutputFile();

    Logger LOG = Logger.getLogger(BTSimBatch.class.getName()); //log variable, the attribute would not read "./configuration/logging.properties

    for (int i = 0; i < parametersValues.size(); i++) {
        JSONObject jo = (JSONObject) parametersValues.get(i);
        LOG.info("Parameters " + jo.toString());
        if (i < this.experimentConducted) {//skip experiments already conducted
            LOG.info("ALREADY DONE IN PREVIOUS EXECUTION (" + i + " of " + parametersValues.size() + ")");
            continue;
        }

        for (int seed = 0; seed < NSEEDS; seed++) {
            LOG.info("Seed: " + seed);
            BTSim bt = new BTSim(seed);
            bt.setParametersSetForBatch(jo);
            bt.start();

            while (bt.schedule.step(bt)) {
            } //execute simulation until finishing

            for (BatchExperimentsResults r : resultsForDatasets) {//for each dataset, add distance for the seed
                r.addResultsForSeed(bt, new Long(seed));
            }

        }
        updateOutputJsonFile(i);
        LOG.info("DONE (" + (i + 1) + " of " + parametersValues.size() + ")");

    }

}

From source file:com.starr.smartbuilds.service.DataService.java

public String getSummonerTierFromData(String region, Long summonerID) throws IOException, ParseException {
    try {//from  w  w  w  . j  av  a  2s .  c  om
        String tier = null;
        String data = getSummonerDataFromRiotAPI(region, summonerID);
        System.out.println(data);
        JSONParser parser = new JSONParser();
        JSONObject json = (JSONObject) parser.parse(data);
        System.out.println(json.toString());
        System.out.println("id:" + summonerID.toString());
        JSONArray json_data = (JSONArray) json.get(summonerID.toString());
        for (Object arr : json_data) {
            JSONObject json_arr = (JSONObject) arr;
            String queue = (String) json_arr.get("queue");
            if (queue.equals("RANKED_SOLO_5x5")) {
                tier = (String) json_arr.get("tier");
            }
        }
        if (tier == null) {
            return "UNRANKED";
        } else {
            return tier;
        }
    } catch (FileNotFoundException ex) {
        return "UNRANKED";
    }
}

From source file:control.ParametrizacionServlets.SeleccionarLaboratorios.java

/**
 * //  ww  w  . jav  a  2s . c om
 * Llama al manager y obtiene la informacion de una actividad
 * economica especifica.
 * 
 * @param request
 * @param response 
 */
private void getLaboratorio(HttpServletRequest request, HttpServletResponse response) {

    try {

        //Obtenemos los parametros
        int codigo = Integer.parseInt(request.getParameter("codigo"));

        //Obtenemos La informacion del manager
        Laboratorios manager = new Laboratorios();
        JSONObject jsonArray = manager.getLaboratorio(codigo);

        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        response.getWriter().write(jsonArray.toString());

    } catch (Exception ex) {
        //Logger.getLogger(SeleccionarActEconomica.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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 {//from  w w w .  j a va  2s.  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();
    }
}

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

@GET
public Response search(@QueryParam("contextQuery") String query, @QueryParam("timeQuery") String timeQuery,
        @QueryParam("n") int n) {
    try {/*from  ww  w.  j ava 2s .  c  o  m*/
        SearchServiceWrapper instance = SearchServiceWrapper.getInstance(
                ServerConfig.getInstance().getProperty("search.language"),
                ServerConfig.getInstance().getProperty("search.index"));
        List<SearchResult> search = instance.getSearch().search(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(SearchService.class.getName()).log(Level.SEVERE, null, ex);
        return Response.serverError().build();
    }
}

From source file:com.consol.citrus.demo.devoxx.service.ReportService.java

/**
 * Construc JSON report data.//  w w w.  j  a  va 2 s .  c  o  m
 * @return
 */
public String json() {
    JSONObject jsonReport = new JSONObject();
    for (Map.Entry<String, AtomicInteger> goods : report.entrySet()) {
        jsonReport.put(goods.getKey(), goods.getValue().get());
    }
    return jsonReport.toString();
}

From source file:com.dubture.twig.core.model.TwigCallable.java

@SuppressWarnings("unchecked")
@Override/* ww  w  .  j  av  a  2 s . c om*/
public String getMetadata() {

    JSONObject data = new JSONObject();
    data.put(PHPCLASS, phpClass);
    data.put(DOC, getDocString());
    data.put(ARGS, filterArguments);
    data.put(INTERNAL, internalFunction);

    return data.toString();
}