Example usage for org.json.simple JSONObject toJSONString

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

Introduction

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

Prototype

public String toJSONString() 

Source Link

Usage

From source file:ClubImpl.java

public String getFAQ() {
    JSONParser parser = new JSONParser();

    Object obj = null;/*from  w w  w  . java  2  s.c o  m*/
    try {
        File f = new File(".");
        System.out.println(f.getAbsolutePath());
        File relative = new File("FAQs.json");
        obj = parser.parse(new FileReader(relative));
    } catch (Exception ex) {
        Logger.getLogger(ClubImpl.class.getName()).log(Level.SEVERE, null, ex);
    }

    JSONObject jsonObject = (JSONObject) obj;
    return jsonObject.toJSONString();

}

From source file:com.appzone.sim.services.handlers.AbstractServiceHandler.java

@Override
public String serve(HttpServletRequest request) {

    logger.debug("start serving request");
    if (keywordMatcher.match(request)) {
        return doProcess(request);
    } else {/*from www  .  ja  v a2  s .c o m*/

        if (nextServiceHandler != null) {
            return nextServiceHandler.serve(request);
        } else {
            logger.debug("cannot find any Handler to serve");
            JSONObject json = new JSONObject();
            json.put("error", "no handler found");

            return json.toJSONString();
        }

    }
}

From source file:com.appzone.sim.services.handlers.PhoneRegistrationServiceHandler.java

@Override
protected String doProcess(HttpServletRequest request) {

    String phoneNo = request.getParameter(KEY_PHONE_NO);
    // converting to md5
    phoneNo = getMD5(phoneNo);/*from  w w  w. j a  v  a 2  s  .  c o m*/

    Phone phone = new Phone(phoneNo);

    logger.debug("adding a new phone: {}", phoneNo);
    phoneRepository.add(phone);

    JSONObject json = new JSONObject();
    json.put(JSON_KEY_MD5_PHONE_NO, phoneNo);

    return json.toJSONString();
}

From source file:CategoryServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w  w  w  .  j a  v a  2 s  .co  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */

        try {
            BufferedReader br = null;
            String price_range = request.getParameter("price_range");
            System.out.println(price_range);

            if (price_range.equals("null"))
                response.sendRedirect("Home.html");
            else {
                HttpSession session = request.getSession();
                session.setAttribute("price_range", price_range);
                br = new BufferedReader(new FileReader("Path to your questionnaire files"));
            }

            WriteQuestionnaireJSON obj = new WriteQuestionnaireJSON();

            String line;
            int i = 1;
            while ((line = br.readLine()) != null) {
                obj.buildJSON(line + "?", "Q" + i);
                i++;
            }
            JSONObject x = obj.write();
            out.println(x.toJSONString());
        } catch (Exception e) {
            out.println(e.getMessage());

        }
    }
}

From source file:com.modeln.batam.connector.wrapper.Pair.java

@SuppressWarnings("unchecked")
public String toJSONString() {
    JSONObject obj = new JSONObject();
    obj.put("name", name);
    obj.put("value", value);

    return obj.toJSONString();
}

From source file:com.nubits.nubot.testsmanual.TestRPCLiquidityInfo.java

private void testGetInfo() {
    if (Global.rpcClient.isConnected()) {
        JSONObject responseObject = Global.rpcClient.getInfo();
        LOG.info(responseObject.toJSONString());
    } else {//from  ww w.  j ava  2s. c  o m
        LOG.error("Nu Client offline. ");
    }
}

From source file:com.nubits.nubot.tests.TestRPC.java

private void testGetInfo() {
    if (Global.rpcClient.isConnected()) {
        JSONObject responseObject = Global.rpcClient.getInfo();
        LOG.info(responseObject.toJSONString());
    } else {/*from w  w  w.  jav a 2s  . com*/
        LOG.severe("Nu Client offline. ");
    }
}

From source file:com.tjackiw.graylog2.plugin.jira.JiraIssue.java

public String toJSONString() {
    JSONObject project = new JSONObject();
    project.put("key", projectKey);

    JSONObject issuetype = new JSONObject();
    issuetype.put("name", issueType);

    JSONObject level = new JSONObject();
    level.put("name", priority);

    JSONArray labelList = new JSONArray();
    String[] labelArr = labels.split("\\,");
    for (String s : labelArr) {
        labelList.add(s);//from w w  w  .jav  a2 s.co  m
    }

    JSONArray componentList = new JSONArray();
    String[] compArr = components.split("\\,");
    for (String s : compArr) {
        JSONObject hash = new JSONObject();
        hash.put("name", s);
        componentList.add(hash);
    }

    JSONObject obj = new JSONObject();
    obj.put("summary", title);
    obj.put("description", description);
    obj.put("project", project);
    obj.put("issuetype", issuetype);
    obj.put("labels", labelList);
    obj.put("components", componentList);
    obj.put("priority", level);

    JSONObject fields = new JSONObject();
    fields.put("fields", obj);

    return fields.toJSONString();
}

From source file:org.kitodo.data.index.elasticsearch.type.BatchType.java

@SuppressWarnings("unchecked")
@Override/* w  w w . ja va 2s  .co  m*/
public HttpEntity createDocument(Batch batch) {

    LinkedHashMap<String, String> orderedBatchMap = new LinkedHashMap<>();
    orderedBatchMap.put("title", batch.getTitle());
    String type = batch.getType() != null ? batch.getType().toString() : "null";
    orderedBatchMap.put("type", type);

    JSONArray processes = new JSONArray();
    List<Process> batchProcesses = batch.getProcesses();
    for (Process process : batchProcesses) {
        JSONObject processObject = new JSONObject();
        processObject.put("id", process.getId().toString());
        processes.add(processObject);
    }

    JSONObject batchObject = new JSONObject(orderedBatchMap);
    batchObject.put("processes", processes);

    return new NStringEntity(batchObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:com.couragelabs.logging.GlobalContextSocketAppender.java

/**
 * If you call setGlobalContext with "test" you will receive
 * {"global":"test"} out of this method. Overly clever? I think not! ;-)
 *
 * @return The fully processed global context property, serialized as JSON.
 *//*  w  ww  .  j  a  v  a 2  s . com*/
@SuppressWarnings("unchecked")
public String getGlobalContext() {
    if (globalContext != null) {
        JSONObject o = new JSONObject();
        o.putAll(globalContext);
        String globalContextStr = o.toJSONString();
        System.out.println(globalContextStr);
        return globalContextStr;
    }
    return null;
}