List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:com.telefonica.iot.cygnus.backends.http.JsonResponseTest.java
/** * Sets up tests by creating a unique instance of the tested class, and by * defining the behaviour of the mocked classes. * //w w w . java 2 s .c o m * @throws Exception */ @Before public void setUp() throws Exception { // set up the instance of the tested class JSONObject obj = new JSONObject(); obj.put("test", "test"); Header[] headers = { new BasicHeader("Content-type", "application/x-www-form-urlencoded"), new BasicHeader("Content-type", "application/x-www-form-urlencoded"), new BasicHeader("Accep", "text/html,text/xml,application/xml"), new BasicHeader("Connection", "keep-alive"), new BasicHeader("keep-alive", "115"), new BasicHeader( "User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.2) Firefox/3.6.2") }; response = new JsonResponse(obj, 200, "OK", null); }
From source file:io.personium.client.EntityTypeManager.java
/** * This method creates an EntityType from EntityType object. * @param obj EntityType object//from ww w . ja v a 2 s . com * @return EntityType object that is created * @throws DaoException Exception thrown */ @SuppressWarnings("unchecked") public EntityType create(EntityType obj) throws DaoException { JSONObject body = new JSONObject(); body.put("Name", obj.getName()); JSONObject json = internalCreate(body); obj.initialize(this.accessor, json); return obj; }
From source file:com.conwet.silbops.msg.PublishMsg.java
@Override @SuppressWarnings("unchecked") public JSONObject getPayloadAsJSON() { JSONObject json = new JSONObject(); json.put("notification", notification.toJSON()); json.put("context", context.toJSON()); return json;//from w ww.j ava2 s .c om }
From source file:com.starr.smartbuilds.service.BuildService.java
public String buildData(Build build, List<Block> blocks) { JSONObject json_build = new JSONObject(); json_build.put("title", build.getName()); json_build.put("type", "custom"); json_build.put("map", "SR"); json_build.put("mode", "any"); json_build.put("type", "custom"); JSONArray json_blocks = new JSONArray(); for (Block block : blocks) { JSONObject json_block = new JSONObject(); json_block.put("type", block.getName()); JSONArray json_items = new JSONArray(); for (Item item : block.getItems()) { JSONObject json_item = new JSONObject(); json_item.put("id", item.getId() + ""); json_item.put("count", 1); json_items.add(json_item);//from ww w .j a v a 2 s . c om } json_block.put("items", json_items); json_blocks.add(json_block); } json_build.put("blocks", json_blocks); return json_build.toString(); }
From source file:com.conwet.silbops.msg.ContextMsg.java
@Override @SuppressWarnings("unchecked") public JSONObject getPayloadAsJSON() { JSONObject json = new JSONObject(); json.put("context", context.toJSON()); json.put("id", id); return json;// w ww .j av a 2 s . c om }
From source file:com.facebook.tsdb.tsdash.server.data.DataTable.java
@SuppressWarnings("unchecked") public JSONObject toJSONObject() { JSONObject result = new JSONObject(); result.put("cols", generateColumns()); result.put("rows", generateRows()); return result; }
From source file:control.UsuariosServlets.ActualizarUsuarios.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* w ww. j a v a 2s. co m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Integer respuesta = 0; try { String usuario = request.getParameter("descripcion"); Integer rol = Integer.parseInt(request.getParameter("rol")); Integer codigo = Integer.parseInt(request.getParameter("codigo")); Usuarios manager = new Usuarios(); respuesta = manager.actualizarUsuarios(usuario, rol, codigo); //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); JSONObject jsonObject = new JSONObject(); jsonObject.put("error", respuesta); response.getWriter().write(jsonObject.toString()); } catch (Exception ex) { //Armamos la respuesta JSON y la enviamos response.setContentType("application/json"); JSONObject jsonObject = new JSONObject(); jsonObject.put("error", respuesta); response.getWriter().write(jsonObject.toString()); } }
From source file:ESDemo.java
@SuppressWarnings("unchecked") private JSONObject intialiseJSONObject() { if (!(hcAPI.getEnvironmentData().getProcessId() > 0)) { System.out.print("initialising data ."); while (!(hcAPI.getEnvironmentData().getProcessId() > 0)) { try { System.out.print("."); Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace();//from w ww . j a va2 s .c o m } } System.out.println(" initialisation complete"); } JSONObject obj = new JSONObject(); obj.put("hostName", hcAPI.getEnvironmentData().getHostName()); obj.put("pid", hcAPI.getEnvironmentData().getProcessId()); obj.put("commandLine", hcAPI.getEnvironmentData().getJavaCommandLine().toString()); obj.put("agentPort", agentPortNum); return obj; }
From source file:backend.Message.java
@Override public JSONObject jsonize() { JSONObject o = new JSONObject(); o.put("sender", m_user_a); o.put("receiver", m_user_b); o.put("content", m_content); return o;// w w w . j av a2s . c o m }
From source file:com.imagelake.earnings.Servlet_EarningsValues.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {/*from ww w . ja v a 2 s . c o m*/ String uid = request.getParameter("uid"); if (uid != null && !uid.equals("")) { uidd = Integer.parseInt(uid); PaymentPreferences pp = ppimp.getPendingEarning(uidd, 1); double pd = 00.00; double ad = 00.00; if (pp != null) { pd = pp.getAmount(); DecimalFormat df1 = new DecimalFormat("#.##"); pd = Double.valueOf(df1.format(pd)); } SellerIncome sin = sidi.getSellerIncome(uidd); ad = sin.getTotal(); DecimalFormat df = new DecimalFormat("#.##"); ad = Double.valueOf(df.format(ad)); double netamo = ad - pd; DecimalFormat df2 = new DecimalFormat("#.##"); netamo = Double.valueOf(df2.format(netamo)); JSONObject jo = new JSONObject(); jo.put("pe", pd); jo.put("ab", ad); jo.put("ne", netamo); out.write("json=" + jo.toJSONString()); } } catch (Exception e) { e.printStackTrace(); } }