List of usage examples for org.json.simple JSONObject toJSONString
public String toJSONString()
From source file:alexaactions.SmartThingsTemperatureDevices.java
private String getJson(String value, String units) { JSONObject jobj = new JSONObject(); jobj.put("temp", value); jobj.put("units", units); return jobj.toJSONString(); }
From source file:com.aerothai.database.role.RolesResource.java
/** * Retrieves representation of an instance of com.aerothai.RolesResource * @return an instance of java.lang.String *///from www.j a v a 2s .c o m @GET // Produces JSON as response @Produces("application/json") //@Produces("application/xml") public String listRole(@QueryParam("column") String column, @QueryParam("value") String value) { String response = null; String opt = null; RoleService roleService = new RoleService(); System.out.println("List Role All"); if (roleService.isNotNull(column) && roleService.isNotNull(value)) { //System.out.println("column = :"+column+" v =:"+value); opt = " " + column + " = '" + value + "'"; } try { JSONObject roleData = null; roleData = roleService.GetRoleAll(opt); response = roleData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:com.fujitsu.dc.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils.java
/** * ComplexTypePropertyComplexType??NP??. * @param token /*from ww w . j av a 2 s. c o m*/ * @param cell ?? * @param box ?? * @param collection ?? * @param complexTypeName complexType?? * @param complexTypePropertyName complexTypePropertyName?? * @param type ComplexTypeProperty?Type * @param nullable ComplexTypeProperty?Nullable * @param defaultValue ComplexTypeProperty?DefaultValue * @param collectionKind ComplexTypeProperty?collectionKind * @param code ?? * @return ? */ @SuppressWarnings("unchecked") public static TResponse createViaComplexTypePropertyNP(String token, String cell, String box, String collection, String complexTypeName, String complexTypePropertyName, String type, Boolean nullable, String defaultValue, String collectionKind, int code) { // ??? JSONObject body = new JSONObject(); body.put("Name", complexTypePropertyName); body.put("_ComplexType.Name", complexTypeName); body.put("Type", type); body.put("Nullable", nullable); body.put("DefaultValue", defaultValue); body.put("CollectionKind", collectionKind); TResponse res = Http.request("box/odatacol/schema/createViaNP.txt").with("cell", cell).with("box", box) .with("collection", collection).with("accept", MediaType.APPLICATION_JSON) .with("contentType", MediaType.APPLICATION_JSON).with("token", DcCoreConfig.getMasterToken()) .with("entityType", "ComplexType").with("id", complexTypeName) .with("navPropName", "_ComplexTypeProperty").with("body", body.toJSONString()).returns() .statusCode(code).debug(); return res; }
From source file:capabilities.DevicesSO.java
@Override public String dbSearch(String userAgent) throws Exception { String urlInicio, urlCapacidades, urlFim, urlPath; String capacidades = "device_os%0D%0A" // Sistema Operacional + "device_os_version%0D%0A" // Verso do sistema operacional + "model_name%0D%0A" // Modelo do dispositivo + "brand_name%0D%0A" // Marca do dispositivo + "is_wireless_device%0D%0A" // Se um dispositivo movel + "is_tablet%0D%0A" // Se um tablet + "pointing_method"; // Tipo de metodo de entrada // Montagem URL de acesso ao Introspector Servlet WURFL urlPath = "http://localhost:8080/AdapterAPI/"; // Caminho do projeto urlInicio = "introspector.do?action=Form&form=pippo&ua=" + userAgent; urlCapacidades = "&capabilities=" + capacidades; urlFim = "&wurflEngineTarget=performance&wurflUserAgentPriority=OverrideSideloadedBrowserUserAgent"; // Conexo com o Servlet DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(urlPath + urlInicio + urlCapacidades + urlFim); getRequest.addHeader("accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); }/*w w w .ja va 2 s .co m*/ BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String buffer; String dados = ""; //System.out.println("Output from Server .... \n"); while ((buffer = br.readLine()) != null) { dados += buffer; } //System.out.println("Sada:\n\t" + dados); httpClient.getConnectionManager().shutdown(); JSONObject my_obj; JSONParser parser = new JSONParser(); my_obj = (JSONObject) parser.parse(dados); JSONObject capabilities = (JSONObject) my_obj.get("capabilities"); return capabilities.toJSONString(); }
From source file:com.aerothai.database.status.StatussResource.java
/** * Retrieves representation of an instance of com.aerothai.StatussResource * @return an instance of java.lang.String *//*from ww w.j a v a 2 s.c om*/ @GET // Produces JSON as response @Produces("application/json") //@Produces("application/xml") public String listStatus(@QueryParam("column") String column, @QueryParam("value") String value) { String response = null; String opt = null; StatusService statusService = new StatusService(); System.out.println("List Status All"); if (statusService.isNotNull(column) && statusService.isNotNull(value)) { //System.out.println("column = :"+column+" v =:"+value); opt = " " + column + " = '" + value + "'"; } try { JSONObject statusData = null; statusData = statusService.GetStatusAll(opt); response = statusData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:io.personium.test.jersey.box.odatacol.schema.complextypeproperty.ComplexTypePropertyUtils.java
/** * ComplexTypePropertyComplexType??NP??. * @param token // w w w. j a v a 2s.com * @param cell ?? * @param box ?? * @param collection ?? * @param complexTypeName complexType?? * @param complexTypePropertyName complexTypePropertyName?? * @param type ComplexTypeProperty?Type * @param nullable ComplexTypeProperty?Nullable * @param defaultValue ComplexTypeProperty?DefaultValue * @param collectionKind ComplexTypeProperty?collectionKind * @param code ?? * @return ? */ @SuppressWarnings("unchecked") public static TResponse createViaComplexTypePropertyNP(String token, String cell, String box, String collection, String complexTypeName, String complexTypePropertyName, String type, Boolean nullable, String defaultValue, String collectionKind, int code) { // ??? JSONObject body = new JSONObject(); body.put("Name", complexTypePropertyName); body.put("_ComplexType.Name", complexTypeName); body.put("Type", type); body.put("Nullable", nullable); body.put("DefaultValue", defaultValue); body.put("CollectionKind", collectionKind); TResponse res = Http.request("box/odatacol/schema/createViaNP.txt").with("cell", cell).with("box", box) .with("collection", collection).with("accept", MediaType.APPLICATION_JSON) .with("contentType", MediaType.APPLICATION_JSON).with("token", PersoniumUnitConfig.getMasterToken()) .with("entityType", "ComplexType").with("id", complexTypeName) .with("navPropName", "_ComplexTypeProperty").with("body", body.toJSONString()).returns() .statusCode(code).debug(); return res; }
From source file:com.appzone.sim.services.handlers.SendMoServiceHandlerTest.java
public void testServeNormal() throws IOException { final HttpServletRequest request = context.mock(HttpServletRequest.class); final EasyHttp http = context.mock(EasyHttp.class); SendMoServiceHandler handler = new SendMoServiceHandler(Application.getApplication(), http); context.checking(new Expectations() { {/*from w w w . j a va 2 s . c om*/ allowing(request).getParameter(DefaultKewordMatcher.SERVICE_KEYWORD); will(returnValue(SendMoServiceHandler.MATCHING_KEYWORD)); allowing(request).getParameter(SendMoServiceHandler.KEY_ADDRESS); will(returnValue("0714000000")); allowing(request).getParameter(SendMoServiceHandler.KEY_MESSAGE); will(returnValue("mpoll sss 1")); allowing(http); } }); JSONObject json = new JSONObject(); json.put(ServiceHandler.JSON_KEY_RESULT, ""); assertEquals(json.toJSONString(), handler.serve(request)); }
From source file:capabilities.Browser.java
@Override public String dbSearch(String userAgent) throws Exception { String urlInicio, urlCapacidades, urlFim, urlPath; String capacidades = "mobile_browser_version%0D%0A" + "mobile_browser"; // Montagem URL de acesso ao Introspector Servlet WURFL urlPath = "http://localhost:8080/AdapterAPI/"; // Caminho do projeto urlInicio = "introspector.do?action=Form&form=pippo&ua=" + userAgent; urlCapacidades = "&capabilities=" + capacidades; urlFim = "&wurflEngineTarget=performance&wurflUserAgentPriority=OverrideSideloadedBrowserUserAgent"; // Conexo com o Servlet DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(urlPath + urlInicio + urlCapacidades + urlFim); getRequest.addHeader("accept", "application/json"); HttpResponse response = httpClient.execute(getRequest); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); }/*from w w w . j a v a 2s . c om*/ BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String buffer; String dados = ""; //System.out.println("Output from Server .... \n"); while ((buffer = br.readLine()) != null) { dados += buffer; } //System.out.println("Sada:\n\t" + dados); httpClient.getConnectionManager().shutdown(); JSONObject my_obj; JSONParser parser = new JSONParser(); my_obj = (JSONObject) parser.parse(dados); JSONObject capabilities = (JSONObject) my_obj.get("capabilities"); return capabilities.toJSONString(); }
From source file:com.aerothai.database.position.PositionsResource.java
/** * Retrieves representation of an instance of com.aerothai.PositionsResource * @return an instance of java.lang.String *///w w w . j av a2s . co m @GET // Produces JSON as response @Produces("application/json") //@Produces("application/xml") public String listPosition(@QueryParam("column") String column, @QueryParam("value") String value) { String response = null; String opt = null; PositionService positionService = new PositionService(); System.out.println("List Position All"); if (positionService.isNotNull(column) && positionService.isNotNull(value)) { //System.out.println("column = :"+column+" v =:"+value); opt = " " + column + " = '" + value + "'"; } try { JSONObject positionData = null; positionData = positionService.GetPositionAll(opt); response = positionData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:app.model.game.ExeChooserModel.java
public Game getFileStructureAsJSON(Game g) throws SQLException { JSONArray jsonarr = listfJSON("C:\\Users\\Public\\Arcade\\Games\\" + g.getGameID() + "\\game"); g.setFilePathJSON(jsonarr);// ww w . j av a2 s. c o m try (SQLHelper sql = new SQLHelper()) { ResultSet rs = sql.execQuery("SELECT executePath FROM games WHERE ID = " + g.getGameID()); if (rs.next()) { JSONObject obj = new JSONObject(); obj.put("file", rs.getString("executePath")); g.setFullFilePath(obj.toJSONString()); } } return g; }