List of usage examples for org.json.simple JSONObject toJSONString
public String toJSONString()
From source file:com.aerothai.database.model.ModelsResource.java
/** * Retrieves representation of an instance of com.aerothai.ModelsResource * @return an instance of java.lang.String *//*from www . j a v a2s. c o m*/ @GET // Produces JSON as response @Produces("application/json") //@Produces("application/xml") public String listModel(@QueryParam("idunit") int idunit, @QueryParam("column") String column, @QueryParam("value") String value) { String response = null; String opt = null; ModelService modelService = new ModelService(); System.out.println("List Model All"); if (modelService.isNotNull(column) && modelService.isNotNull(value)) { //System.out.println("column = :"+column+" v =:"+value); opt = " " + column + " = '" + value + "'"; } try { JSONObject modelData = null; modelData = modelService.GetModelAll(idunit, opt); response = modelData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:com.aerothai.database.unit.UnitsResource.java
/** * Retrieves representation of an instance of com.aerothai.UnitsResource * @return an instance of java.lang.String */// w ww .j a v a 2 s .co m @GET // Produces JSON as response @Produces("application/json") //@Produces("application/xml") public String listUnit(@QueryParam("action") String action, @QueryParam("column") String column, @QueryParam("value") String value) { String response = null; String opt = null; UnitService unitService = new UnitService(); System.out.println("List Unit All"); if (unitService.isNotNull(column) && unitService.isNotNull(value)) { //System.out.println("column = :"+column+" v =:"+value); opt = " " + column + " = '" + value + "'"; } if (!unitService.isNotNull(action)) { action = "0"; } try { JSONObject unitData = null; unitData = unitService.GetUnitAll(action, opt); response = unitData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:capabilities.Display.java
@Override public String dbSearch(String userAgent) throws Exception { String urlInicio, urlCapacidades, urlFim, urlPath; String capacidades = "resolution_width%0D%0A" // Largura da tela em pixels + "resolution_height%0D%0A" // Altura da tela em pixels + "columns%0D%0A" // Numero de colunas apresentadas + "rows%0D%0A" // Numero de linhas apresentadas + "physical_screen_width%0D%0A" // Largura da tela em milimetros + "physical_screen_height%0D%0A" // Altura da tela em milimetros + "dual_orientation"; // Se pode ter duas orientacoes // 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. j a v a 2 s . c o 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.job.JobsResource.java
/** * Retrieves representation of an instance of com.aerothai.JobsResource * @return an instance of java.lang.String */// w w w . java 2 s . c o m @GET // Produces JSON as response @Produces("application/json") //@Produces("application/xml") public String listJob(@QueryParam("idunit") int idunit, @QueryParam("column") String column, @QueryParam("value") String value) { String response = null; String opt = null; JobService jobService = new JobService(); System.out.println("List Job All"); if (jobService.isNotNull(column) && jobService.isNotNull(value)) { //System.out.println("column = :"+column+" v =:"+value); opt = " " + column + " = '" + value + "'"; } try { JSONObject jobData = null; jobData = jobService.GetJobAll(idunit, opt); response = jobData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:com.imagelake.android.changephoneno.Servlet_ChangePhoneno.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {//from w ww . j a v a 2 s. com String type = request.getParameter("type"); if (type != null) { String uid = request.getParameter("uid"); if (type.equals("load_phone")) { if (uid != null) { User u = udi.getUser(Integer.parseInt(uid)); if (u != null) { JSONObject jo = new JSONObject(); jo.put("phn", u.getPhone()); System.out.println(jo.toJSONString()); out.write("json=" + jo.toJSONString()); } else { out.write("msg=Internal server error,Please try again later."); } } else { out.write("msg=Internal server error,Please try again later."); } } else if (type.equals("update_phone")) { String phn = request.getParameter("phn"); if (phn != null) { boolean k = udi.updatePhoneNo(Integer.parseInt(uid), phn); if (k) { out.write("msg=Successfully Completed."); } else { out.write("msg=Unable to complete the action,Please try again later."); } } else { out.write("msg=Internal server error,Please try again later."); } } } else { out.write("msg=Internal server error,Please try again later."); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.aerothai.database.devicetype.DeviceTypesResource.java
/** * Retrieves representation of an instance of com.aerothai.DeviceTypesResource * @return an instance of java.lang.String *//*from w w w .j a v a 2 s . c o m*/ @GET // Produces JSON as response @Produces("application/json") //@Produces("application/xml") public String listDeviceType(@QueryParam("column") String column, @QueryParam("value") String value) { String response = null; String opt = null; DeviceTypeService deviceTypeService = new DeviceTypeService(); System.out.println("List DeviceType All"); if (deviceTypeService.isNotNull(column) && deviceTypeService.isNotNull(value)) { //System.out.println("column = :"+column+" v =:"+value); opt = " " + column + " = '" + value + "'"; } try { JSONObject deviceTypeData = null; deviceTypeData = deviceTypeService.GetDeviceTypeAll(opt); response = deviceTypeData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:hudson.plugins.memegen.MemegeneratorResponseException.java
MemegeneratorJSONException(JSONObject obj, String key) { super("Missing key in JSON response: " + key + ", full response: " + obj.toJSONString()); }
From source file:copter.HCSR04.java
@Override public void run() { delay(2000);//from www . ja v a2s . c o m while (streamData) { float distance = getDistance(trigger, echo); JSONObject res = new JSONObject(); res.put("fron_distance_cm", distance); conn.send(res.toJSONString()); delay(100); } }
From source file:com.aerothai.database.os.OssResource.java
/** * Retrieves representation of an instance of com.aerothai.OssResource * @return an instance of java.lang.String *//*from w ww . j av a 2s . c om*/ @GET // Produces JSON as response @Produces("application/json") //@Produces("application/xml") public String listOs() { String response = null; System.out.println("List Os All"); try { JSONObject osData = null; OsService osService = new OsService(); osData = osService.GetOsAll(); response = osData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:com.aerothai.database.servicetype.ServicetypeSResource.java
/** * Retrieves representation of an instance of com.aerothai.ServicetypeSResource * @return an instance of java.lang.String *///from www .ja v a 2 s .co m @GET // Produces JSON as response @Produces("application/json") //@Produces("application/xml") public String listServicetype(@QueryParam("column") String column, @QueryParam("value") String value) { String response = null; String opt = null; ServicetypeService servicetypeService = new ServicetypeService(); System.out.println("List Servicetype All"); if (servicetypeService.isNotNull(column) && servicetypeService.isNotNull(value)) { //System.out.println("column = :"+column+" v =:"+value); opt = " " + column + " = '" + value + "'"; } try { JSONObject servicetypeData = null; servicetypeData = servicetypeService.GetServicetypeAll(opt); response = servicetypeData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }