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:it.polimi.geinterface.DAO.Entity.java

public static JSONObject wrapJSONProperties(JSONObject obj) {
    JSONObject ret = new JSONObject();
    ret.put(JsonStrings.PROPERTIES, obj);
    return ret;/*from   w  ww .jav a2s .c  o  m*/
}

From source file:RemoteDeviceDiscovery.java

public static String deviceJson(RemoteDevice d) {

    String address = d.getBluetoothAddress();
    address = address.substring(0, 10) + ":" + address.substring(10, address.length());
    address = address.substring(0, 8) + ":" + address.substring(8, address.length());
    address = address.substring(0, 6) + ":" + address.substring(6, address.length());
    address = address.substring(0, 4) + ":" + address.substring(4, address.length());
    address = address.substring(0, 2) + ":" + address.substring(2, address.length());
    String name = "";
    try {//from  w w w.  jav a  2  s.  co  m
        name = d.getFriendlyName(false);
    } catch (IOException e) {
        try {
            name = d.getFriendlyName(false);
        } catch (IOException e2) {
        }
    }

    JSONObject obj = new JSONObject();
    obj.put("clientVersion", "1.0");
    obj.put("clientType", "bluecat");
    obj.put("timestamp", new Date().getTime());
    obj.put("bluetoothAddress", address);
    obj.put("bluetoothName", name);

    return obj.toString();
}

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

protected static void leerUsuariosMultiplesId(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList<UsuarioEntity> usuarios = new ArrayList<>();
    usuarios = CtrlAdmin.leerMultiplesUsuarios(Integer.parseInt(request.getParameter("1")),
            Integer.parseInt(request.getParameter("2"))); // id del usuario

    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);/* ww  w .  ja v a  2 s.  c om*/
    }
    out.print(list1);
}

From source file:ch.newscron.encryption.Encryption.java

/**
 * Computes the max number of available characters, considering the initial URL, base64, AES, MD5 hash and JSON object.
 * !! Available characters do not include the follow special characters (which require > 1 bytes): "/", "\", """, "'" and any kind of accents!!
 * @param initialURL ("http://domain/path")
 * @return the max number of available characters for the four fields (customerID, reward1, reward2, validity)
 *///from w w  w  .j  ava 2s .co  m
public static Integer availableParameterLength(String initialURL) {
    try {
        JSONObject emptyData = new JSONObject();
        emptyData.put("custID", "");
        emptyData.put("rew1", "");
        emptyData.put("rew2", "");
        emptyData.put("val", "");
        emptyData.put("hash", "");

        //Max size of URL for Internet Explorer... :-(
        int maxURLSize = 2000;

        //Remove size of initial url (host+domain)
        maxURLSize -= initialURL.getBytes("UTF-8").length;

        //Base64 ratio of 3/4
        maxURLSize = (int) Math.ceil((maxURLSize * 3) / 4);

        //Maximum number of blocks available * 16
        maxURLSize = (int) Math.floor(maxURLSize / 16) * 16;

        //Remove size of hash (16 bytes) and empty JSON (without fields)
        maxURLSize -= (16 + emptyData.toJSONString().getBytes("UTF-8").length);

        //Remaining number of characters available
        return maxURLSize;

    } catch (Exception e) {
    }

    return null;
}

From source file:msuresh.raftdistdb.TestAtomix.java

private static void UpdatePortNumber() {
    try {/*from   ww  w  .j  av  a2s.c  om*/
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(new FileReader(Constants.STATE_LOCATION + "global.info"));
        JSONObject jsonObject = (JSONObject) obj;
        jsonObject.put("currentCount", portId);
        try (FileWriter file = new FileWriter(Constants.STATE_LOCATION + "global.info")) {
            file.write(jsonObject.toJSONString());
        }
    } catch (Exception e) {

    }
}

From source file:net.duckling.ddl.util.StringUtil.java

License:asdf

/**
 * ?:*<>\"|?\/\\,json/*w w w.ja v a2  s.  co m*/
 * @param req
 * @param resp
 * @param params
 * @return
 */
@SuppressWarnings({ "deprecation" })
public static boolean illCharCheck(HttpServletRequest req, HttpServletResponse resp, String... params) {
    if (params == null || params.length == 0) {
        return false;
    }
    for (String p : params) {
        String s = req.getParameter(p);
        if (StringUtils.isNotEmpty(s) && pattern.matcher(s).find()) {
            if (resp != null) {
                JSONObject obj = new JSONObject();
                obj.put("success", false);
                obj.put("result", false);
                obj.put("param", s);
                obj.put("message", "??<>:\"|*?/\\");
                JsonUtil.writeJSONObject(resp, obj);
            }
            return true;
        }
    }
    return false;
}

From source file:hoot.services.controllers.job.JobControllerBase.java

protected static JSONObject createReflectionJobReq(JSONArray args, String className, String methodName) {
    JSONObject command = new JSONObject();
    command.put("exectype", "reflection");
    command.put("class", className);
    command.put("method", methodName);
    command.put("params", args);

    return command;
}

From source file:hoot.services.controllers.job.JobControllerBase.java

static JSONObject createReflectionSycJobReq(JSONArray args, String className, String methodName) {
    JSONObject command = new JSONObject();
    command.put("exectype", "reflection_sync");
    command.put("class", className);
    command.put("method", methodName);
    command.put("params", args);

    return command;
}

From source file:com.p000ison.dev.copybooks.util.Helper.java

public static String fromListToJSONString(String key, List<String> list) {

    JSONObject json = new JSONObject();

    JSONArray array = new JSONArray();
    array.addAll(list);/*ww  w.  j  a v a  2s  .c  om*/

    json.put(key, array);

    return json.toString();
}

From source file:hoot.services.controllers.job.JobControllerBase.java

protected static JSONObject createReflectionJobReq(JSONArray args, String className, String methodName,
        String internalJobId) {//  www .  j a v  a2 s  . c o m
    JSONObject command = new JSONObject();
    command.put("exectype", "reflection");
    command.put("class", className);
    command.put("method", methodName);
    command.put("internaljobid", internalJobId);
    command.put("params", args);

    return command;
}