List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:co.edu.unal.arqdsoft.presentacion.JSON.java
/** * //from w w w .j ava2 s.c om * @param arg * @return JSON String del ojbeto parametro */ public static String toString(Respuesta arg) { JSONObject obj = new JSONObject(); obj.put("error", arg.getError()); obj.put("contenido", arg.getContenido().toJSON()); return obj.toJSONString(); }
From source file:co.edu.unal.arqdsoft.presentacion.JSON.java
/** * /*from ww w. java2 s . c o m*/ * @param request * @return JSONObject con los parametros del request * @throws Exception */ public static JSONObject toObject(HttpServletRequest request) throws Exception { if (request.getParameter("accion") != null) {//Servidor independiente JSONObject r = new JSONObject(); r.put("accion", request.getParameter("accion")); r.put("datos", request.getParameter("datos")); return r; } else {//Servidor base netbeans InputStream is = request.getInputStream(); byte[] charr = new byte[is.available()]; is.read(charr); return (JSONObject) JSONValue.parse(new String(charr, "UTF-8")); } }
From source file:mml.handler.json.Dialect.java
/** * Wrap a dialect doc in some more JSON for storage * @param dialect the dialect file/* www.j av a 2 s .co m*/ * @param docid its docid * @return a BSON basic document */ public static JSONObject wrap(JSONObject dialect, String docid) { JSONObject wrap = new JSONObject(); wrap.put(JSONKeys.BODY, dialect.toJSONString()); wrap.put(JSONKeys.DOCID, docid); return wrap; }
From source file:JavaCloud.Cloud.java
public static Cloud register(String address, String login, String password, String name, String surname, String email) throws CoreException { JSONObject object = new JSONObject(); object.put("login", login); object.put("password", password); object.put("name", name); object.put("surname", surname); object.put("email", email); Utils.request(address, "/user/user/register/", object); return new Cloud(address, login, password); }
From source file:net.cyberninjapiggy.apocalyptic.misc.UUIDFetcher.java
@SuppressWarnings("unchecked") private static String buildBody(List<String> names) { List<JSONObject> lookups = new ArrayList<>(); for (String name : names) { JSONObject obj = new JSONObject(); obj.put("name", name); obj.put("agent", AGENT); lookups.add(obj);//www . j a va2 s . c o m } return JSONValue.toJSONString(lookups); }
From source file:com.punyal.medusaserver.californiumServer.core.MedusaValidation.java
public static Client check(String medusaServerAddress, String myTicket, String ticket) { CoapClient coapClient = new CoapClient(); Logger.getLogger("org.eclipse.californium.core.network.CoAPEndpoint").setLevel(Level.OFF); Logger.getLogger("org.eclipse.californium.core.network.EndpointManager").setLevel(Level.OFF); Logger.getLogger("org.eclipse.californium.core.network.stack.ReliabilityLayer").setLevel(Level.OFF); CoapResponse response;/*from w ww. j a v a2s. c o m*/ coapClient.setURI(medusaServerAddress + "/" + MEDUSA_SERVER_VALIDATION_SERVICE_NAME); JSONObject json = new JSONObject(); json.put(JSON_MY_TICKET, myTicket); json.put(JSON_TICKET, ticket); response = coapClient.put(json.toString(), 0); if (response != null) { //System.out.println(response.getResponseText()); try { json.clear(); json = (JSONObject) JSONValue.parse(response.getResponseText()); long expireTime = (Long) json.get(JSON_TIME_TO_EXPIRE) + (new Date()).getTime(); String userName = json.get(JSON_USER_NAME).toString(); String[] temp = json.get(JSON_ADDRESS).toString().split("/"); String address; if (temp[1] != null) address = temp[1]; else address = "0.0.0.0"; Client client = new Client(InetAddress.getByName(address), userName, null, UnitConversion.hexStringToByteArray(ticket), expireTime); return client; } catch (Exception e) { } } else { // TODO: take } return null; }
From source file:net.jselby.pc.network.JoinHandler.java
public static void join(ChannelHandlerContext ctx, Client cl) { ConnectedClient client = (ConnectedClient) cl; System.out.println(cl.name + "[" + ctx.channel().remoteAddress() + "] logged in with entity id " + cl.id + " at ([world] " + cl.x + ", " + cl.y + ", " + cl.z + ")"); // Welcome messages PacketOutChatMessage joinMsg = new PacketOutChatMessage(); joinMsg.message = ChatMessage.convertToJson("Welcome to the server!"); joinMsg.message.json.put("color", "gold"); cl.writePacket(joinMsg);//w ww. java 2s .c o m joinMsg.message = ChatMessage.convertToJson("This server is running PoweredCube - http://pc.jselby.net"); joinMsg.message.json.put("color", "gold"); JSONObject clickEvent = new JSONObject(); clickEvent.put("action", "open_url"); clickEvent.put("value", "http://pc.jselby.net"); joinMsg.message.json.put("clickEvent", clickEvent); cl.writePacket(joinMsg); joinMsg.message = ChatMessage.convertToJson("Any number of bugs can occur. You have been warned!"); joinMsg.message.json.put("color", "red"); cl.writePacket(joinMsg); // Spawn entity for (Client c : PoweredCube.getInstance().clients .toArray(new Client[PoweredCube.getInstance().clients.size()])) { PlayerDisplayer.showPlayer(client, c); } BukkitPlayer p = new BukkitPlayer(cl); PoweredCube.getInstance().players.add(p); PoweredCube.getInstance().clients.add(cl); joinMsg.message = ChatMessage.convertToJson(cl.displayName + " joined the server."); PoweredCube.getInstance().distributePacket(joinMsg); }
From source file:com.mum.edu.cs472.dictServlet.java
public static JSONArray convertToJSON(ResultSet resultSet) throws Exception { JSONArray jsonArray = new JSONArray(); while (resultSet.next()) { int total_rows = resultSet.getMetaData().getColumnCount(); JSONObject obj = new JSONObject(); for (int i = 0; i < total_rows; i++) { obj.put(resultSet.getMetaData().getColumnLabel(i + 1).toLowerCase(), resultSet.getObject(i + 1)); jsonArray.add(obj);/*from w w w.j ava2 s.c o m*/ } } return jsonArray; }
From source file:me.sonarbeserk.lockup.utils.UUIDFetcher.java
@SuppressWarnings("unchecked") private static String buildBody(List<String> names) { List<JSONObject> lookups = new ArrayList<JSONObject>(); for (String name : names) { JSONObject obj = new JSONObject(); obj.put("name", name); obj.put("agent", AGENT); lookups.add(obj);//from w w w. j a v a 2 s . c o m } return JSONValue.toJSONString(lookups); }
From source file:at.ac.tuwien.infosys.jcloudscale.datastore.driver.couchdb.CouchDBUtil.java
/** * Add id and revision to the content of a given request * * @param request the given request//from w w w.ja va2s . c o m * @param id the id to add * @param revision the revision to add * @return the modified request */ public static Request addIdAndRevisionToContent(Request request, String id, String revision) { JSONParser parser = new JSONParser(); try { JSONObject jsonObject = (JSONObject) parser.parse((String) request.getContent()); jsonObject.put("_id", id); jsonObject.put("_rev", revision); String jsonString = jsonObject.toJSONString(); log.info("Updated Request content with id and rev: " + jsonString); return new Request.Builder(request.getProtocolType(), request.getRequestType(), request.getUrl(), request.getHost(), request.getPort()).contentType(request.getContentType()).content(jsonString) .build(); } catch (ParseException e) { throw new DatastoreException("Error parsing JSON to add revision: " + e.getMessage()); } }