Example usage for org.json.simple JSONObject put

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

Introduction

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

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void consultarUsuariosEnTallerId(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList<UsuarioEntity> usuarios = new ArrayList<>();
    usuarios = CtrlAdmin.obtenerUsuariosEnTaller(Integer.parseInt(request.getParameter("3")),
            Integer.parseInt(request.getParameter("2")), Integer.parseInt(request.getParameter("1")));

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();

    JSONArray list1 = new JSONArray();
    for (UsuarioEntity usuario : usuarios) {
        JSONObject obj = new JSONObject();
        obj.put("id", usuario.getIdUsuario());
        obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos());
        list1.add(obj);//from w w  w.  ja  v  a  2s . c om
    }
    out.print(list1);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void consultarDocentesEnTallerId(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList<UsuarioEntity> usuarios = new ArrayList<>();
    usuarios = CtrlAdmin.obtenerUsuariosEnTaller(Integer.parseInt(request.getParameter("1")),
            Integer.parseInt(request.getParameter("2")), Integer.parseInt(request.getParameter("3")));

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();

    JSONArray list1 = new JSONArray();
    for (UsuarioEntity usuario : usuarios) {
        JSONObject obj = new JSONObject();
        obj.put("id", usuario.getIdUsuario());
        obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos());
        list1.add(obj);//w ww.  j  a  v a 2 s  .  co  m
    }
    out.print(list1);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void eliminarConvocatoria(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlAdmin.eliminarConvocatoria(Integer.parseInt(request.getParameter("1"))); // id

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);//from w  ww  .j  a v  a  2s  .  c  o  m
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void eliminarTaller(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlAdmin.eliminarTaller(Integer.parseInt(request.getParameter("1"))); // id

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);/*from   w  w w  .  j  a v a 2  s. co m*/
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void consultarUsuariosEnConvocatoriaId(HttpServletRequest request,
        HttpServletResponse response) throws IOException {
    ArrayList<UsuarioEntity> usuarios = new ArrayList<>();
    usuarios = CtrlAdmin.obtenerUsuariosEnConvocatoria(Integer.parseInt(request.getParameter("3")), //id evento
            Integer.parseInt(request.getParameter("2")), //tamao tabla
            Integer.parseInt(request.getParameter("1"))//pagina
    );/*from w ww  .j  a  va 2  s. c  o m*/

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();

    JSONArray list1 = new JSONArray();
    for (UsuarioEntity usuario : usuarios) {
        JSONObject obj = new JSONObject();
        obj.put("id", usuario.getIdUsuario());
        obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos());
        list1.add(obj);
    }
    out.print(list1);
}

From source file:model.Post_store.java

public static void update_post(String title, String content, List<String> comments, List<String> UA_comments,
        int id) {
    JSONObject obj = new JSONObject();
    obj.put("title", title);
    obj.put("content", content);

    JSONArray Jcomments = new JSONArray();
    for (String i : comments) {
        Jcomments.add(i);/*www  .  j  a v a2s . co m*/
    }
    obj.put("comments", comments);

    JSONArray JUA_comments = new JSONArray();
    for (String i : UA_comments) {
        JUA_comments.add(i);
    }
    obj.put("UA_comments", UA_comments);

    try (FileWriter file = new FileWriter(root + "posts/" + id + ".json");) {
        file.write(obj.toJSONString());
        file.flush();
        file.close();

    } catch (IOException e) {
        System.out.println(e);
    }

    //System.out.print(obj);
}

From source file:at.ac.tuwien.dsg.quelle.sesConfigurationsRecommendationService.util.ConvertTOJSON.java

public static String convertTOJSON(MultiLevelRequirements levelRequirements) {
    if (levelRequirements == null) {
        return "{nothing}";
    }//from www. j  av  a 2  s.  c o  m
    JSONObject root = new JSONObject();
    //diff is that in some cases (e.g. condition), name is displayName
    root.put("name", levelRequirements.getName());
    root.put("realName", levelRequirements.getName());
    root.put("type", "" + levelRequirements.getLevel());

    //traverse recursive XML tree
    List<JSONObject> jsonObjects = new ArrayList<>();
    List<MultiLevelRequirements> reqsList = new ArrayList<>();

    reqsList.add(levelRequirements);
    jsonObjects.add(root);

    while (!reqsList.isEmpty()) {
        JSONObject obj = jsonObjects.remove(0);
        MultiLevelRequirements reqs = reqsList.remove(0);

        JSONArray children = new JSONArray();
        for (MultiLevelRequirements childReqs : reqs.getContainedElements()) {
            JSONObject child = new JSONObject();
            child.put("name", childReqs.getName());
            child.put("realName", childReqs.getName());
            child.put("type", "" + childReqs.getLevel());
            children.add(child);

            reqsList.add(childReqs);
            jsonObjects.add(child);
        }

        //add strategies
        for (Strategy strategy : reqs.getOptimizationStrategies()) {
            JSONObject strategyJSON = new JSONObject();
            strategyJSON.put("name", "" + strategy.getStrategyCategory().toString());
            strategyJSON.put("realName", "" + strategy.getStrategyCategory().toString());
            strategyJSON.put("type", "Strategy");
            children.add(strategyJSON);
        }

        //            JSONArray unitReqs = new JSONArray();
        for (Requirements requirements : reqs.getUnitRequirements()) {
            JSONObject child = new JSONObject();
            child.put("name", requirements.getName());
            child.put("realName", requirements.getName());
            child.put("type", "RequirementsBlock");
            children.add(child);

            JSONArray requirementsJSON = new JSONArray();

            for (Requirement requirement : requirements.getRequirements()) {
                JSONObject requirementJSON = new JSONObject();
                requirementJSON.put("name", requirement.getName());
                requirementJSON.put("realName", requirement.getName());
                requirementJSON.put("type", "Requirement");
                //put individual conditions
                JSONArray conditions = new JSONArray();

                for (Condition condition : requirement.getConditions()) {
                    JSONObject conditionJSON = new JSONObject();
                    conditionJSON.put("name", "MUST BE " + condition.toString());
                    conditionJSON.put("type", "Condition");
                    conditionJSON.put("realName", "" + condition.getType());
                    conditions.add(conditionJSON);
                }

                requirementJSON.put("children", conditions);
                requirementsJSON.add(requirementJSON);
            }

            child.put("children", requirementsJSON);

        }

        obj.put("children", children);

    }

    return root.toJSONString();
}

From source file:at.ait.dme.yuma.suite.apps.core.server.annotation.JSONAnnotationHandler.java

@SuppressWarnings("unchecked")
private static JSONObject serializeUser(User user) {
    JSONObject jsonObj = new JSONObject();

    jsonObj.put(KEY_USER_NAME, user.getUsername());
    jsonObj.put(KEY_USER_HASH, user.getGravatarHash());
    jsonObj.put(KEY_USER_URI, user.getUri());

    return jsonObj;
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void crearConvocatoria(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlAdmin.crearConvocatoria(request.getParameter("1"), // nombre
            request.getParameter("2"), // descripcin
            request.getParameter("4"), // fin
            Integer.parseInt(request.getParameter("6")) // cupos
    );/*from w  w  w  .  jav a  2s. co  m*/

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}

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

/**
 * convert List<OFStatistics> to JSONArray
 * @param ofs/*w  w w.  ja  v  a  2  s .co m*/
 * @return JSONArray
 */
public static JSONArray toTableStat(List<OFStatistics> ofs) {

    JSONArray jsonArray = new JSONArray();
    for (OFStatistics ofst : ofs) {

        OFTableStatistics st = (OFTableStatistics) ofst;
        // st.getPortNumber() st.getReceiveBytes();

        FlowscaleController.logger.debug("Maximum Entries {} and and Table id {}", st.getMaximumEntries(),
                st.getTableId());
        FlowscaleController.logger.debug("Name {} and and Table length {}", st.getName(), st.getLength());

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("match_count", st.getMatchedCount());
        jsonObject.put("maximum_entries", st.getMaximumEntries());
        jsonObject.put("name", st.getName());
        jsonObject.put("table_id", st.getTableId());
        jsonObject.put("active_count", st.getActiveCount());

        jsonArray.add(jsonObject);

    }

    return jsonArray;

}