List of usage examples for org.json JSONObject get
public Object get(String key) throws JSONException
From source file:org.wso2.bps.integration.common.clients.bpmn.ActivitiRestClient.java
/** * Method used to find task by using the process instance ID * * @param processInstanceId used to identify task through a process instance * @return String Array containing status and the taskID * @throws IOException//w w w.j a v a 2 s . c o m * @throws JSONException */ public String[] findTaskIdByProcessInstanceID(String processInstanceId) throws IOException, JSONException { String url = serviceURL + "runtime/tasks"; String taskId = ""; HttpHost target = new HttpHost(hostname, port, "http"); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password)); HttpGet httpget = new HttpGet(url); HttpResponse response = httpClient.execute(httpget); String status = response.getStatusLine().toString(); String responseData = EntityUtils.toString(response.getEntity()); JSONObject jsonResponseObject = new JSONObject(responseData); JSONArray data = jsonResponseObject.getJSONArray("data"); int responseObjectSize = Integer.parseInt(jsonResponseObject.get("total").toString()); for (int j = 0; j < responseObjectSize; j++) { if (data.getJSONObject(j).getString("processInstanceId").equals(processInstanceId)) { taskId = data.getJSONObject(j).getString("id"); } } return new String[] { status, taskId }; }
From source file:com.soomla.store.domain.data.BalanceDrivenPriceModel.java
/** * docs in {@link AbstractPriceModel#toJSONObject()} *///from w ww .j av a2s . c o m @Override public JSONObject toJSONObject() throws JSONException { JSONObject parentJsonObject = super.toJSONObject(); JSONObject jsonObject = new JSONObject(); Iterator<?> keys = parentJsonObject.keys(); while (keys.hasNext()) { String key = (String) keys.next(); jsonObject.put(key, parentJsonObject.get(key)); } JSONArray valuesPerBalance = new JSONArray(); for (HashMap<String, Integer> currencyValue : mCurrencyValuePerBalance) { JSONObject currencyValues = new JSONObject(); for (String key : currencyValue.keySet()) { currencyValues.put(key, currencyValue.get(key)); } valuesPerBalance.put(currencyValues); } jsonObject.put(JSONConsts.GOOD_PRICE_MODEL_VALUES, valuesPerBalance); return jsonObject; }
From source file:bpv.neurosky.connector.ThinkGearSocket.java
private void parsePacket(JSONObject data) { Iterator<?> itr = data.keys(); while (itr.hasNext()) { Object e = itr.next();//from w w w . j a v a 2s. c o m String key = e.toString(); try { if (key.matches("poorSignalLevel")) { triggerPoorSignalEvent(data.getInt(e.toString())); } if (key.matches("rawEeg")) { int rawValue = (Integer) data.get("rawEeg"); raw[index] = rawValue; index++; if (index == 512) { index = 0; int rawCopy[] = new int[512]; //TODO: Ajusta para funcionar na implementao atual rawCopy = Arrays.copyOf(raw, raw.length); triggerRawEvent(rawCopy); } } if (key.matches("blinkStrength")) { triggerBlinkEvent(data.getInt(e.toString())); } if (key.matches("eSense")) { JSONObject esense = data.getJSONObject("eSense"); triggerAttentionEvent(esense.getInt("attention")); triggerMeditationEvent(esense.getInt("meditation")); } if (key.matches("eegPower")) { JSONObject eegPower = data.getJSONObject("eegPower"); triggerEEGEvent(eegPower.getInt("delta"), eegPower.getInt("theta"), eegPower.getInt("lowAlpha"), eegPower.getInt("highAlpha"), eegPower.getInt("lowBeta"), eegPower.getInt("highBeta"), eegPower.getInt("lowGamma"), eegPower.getInt("highGamma")); //System.out.println(key); } } catch (Exception ex) { ex.printStackTrace(); } } // }
From source file:org.collectionspace.chain.csp.persistence.services.TestService.java
/** * Tests conversion of a JSON file to XML. This implementation does not compare the * resultant generated XML to an expected XML file. Instead, it converts the resultant * XML back into JSON, and compares that round-trip JSON to an expected JSON file. * /* w w w . j ava 2 s . c o m*/ * @param spec * @param objtype * @param xmlfile Name of the file containing the expected XML (not currently used) * @param jsonfile Name of the file containing JSON to be converted to XML * @param returnedjsonfile Name of the file containing the expected round-trip JSON, converted back from XML * @throws Exception */ private void testJSONXML(Spec spec, String objtype, String xmlfile, String jsonfile, String returnedjsonfile) throws Exception { log.info("Converting JSON to XML for record type " + objtype); Record r = spec.getRecord(objtype); JSONObject j = getJSON(jsonfile); //log.info("Original JSON:\n" + j.toString()); Map<String, Document> parts = new HashMap<String, Document>(); Document doc = null; JSONObject testjson = new JSONObject(); for (String section : r.getServicesRecordPathKeys()) { if (section.equals("common")) { String path = r.getServicesRecordPath(section); String[] record_path = path.split(":", 2); doc = XmlJsonConversion.convertToXml(r, j, section, ""); parts.put(record_path[0], doc); //log.info("After JSON->XML conversion:\n" + doc.asXML()); JSONObject repeatjson = org.collectionspace.chain.csp.persistence.services.XmlJsonConversion .convertToJson(r, doc, "", "common", "", "");// this is where we // specify the // multipart // section // we are considering for (String name : JSONObject.getNames(repeatjson)) { testjson.put(name, repeatjson.get(name)); } //log.info("After XML->JSON re-conversion:\n" + testjson.toString()); } } // convert json -> xml and back to json and see if it still looks the // same.. JSONObject expectedjson = getJSON(returnedjsonfile); boolean result = JSONUtils.checkJSONEquivOrEmptyStringKey(expectedjson, testjson); if (!result) { log.info("Original JSON:\n" + j.toString()); log.info("After JSON->XML conversion:\n" + doc.asXML()); log.info("After XML->JSON re-conversion:\n" + testjson.toString()); } assertTrue("JSON->XML->JSON round-trip for record type: " + objtype + " doesn't match original JSON", result); }
From source file:net.dahanne.gallery3.client.utils.ItemUtils.java
public static String convertJsonStringToUrl(String jsonResult) throws JSONException { JSONObject jsonObject = new JSONObject(jsonResult); return (String) jsonObject.get("url"); }
From source file:org.jkan997.slingbeans.slingfs.FileSystemServer.java
private FileObject loadFileObjectContent(String path, JSONObject jobj) throws Exception { path = StringHelper.normalizePath(path); FileObject res = getCachedObject(path); String[] nameExtArr = StringHelper.extractNameExt(path); res.setName(nameExtArr[0]);//from ww w .ja v a 2 s .c o m res.setExt(nameExtArr[1]); Object typeObj = jobj.get("jcr:primaryType"); res.setFolder(true); if ((typeObj != null) && ("nt:file".equals(typeObj))) { res.setFolder(false); } res.objectModified(); return res; }
From source file:com.mparticle.internal.ConfigManager.java
public Map<String, String> getIntegrationAttributes(int kitId) { Map<String, String> integrationAttributes = new HashMap<String, String>(); JSONObject jsonAttributes = getIntegrationAttributes(); if (jsonAttributes != null) { JSONObject kitAttributes = jsonAttributes.optJSONObject(Integer.toString(kitId)); if (kitAttributes != null) { try { Iterator<String> keys = kitAttributes.keys(); while (keys.hasNext()) { String key = keys.next(); if (kitAttributes.get(key) instanceof String) { integrationAttributes.put(key, kitAttributes.getString(key)); }//from w ww . j a v a 2 s . com } } catch (JSONException e) { } } } return integrationAttributes; }
From source file:com.visionspace.jenkins.vstart.plugin.VSPluginHtmlWriter.java
public boolean doHtmlReport(AbstractBuild build, JSONArray jArrayReport) { try {/*from w w w .ja v a 2 s . co m*/ if (jArrayReport == null) { return false; } FilePath hPath = new FilePath(build.getWorkspace(), build.getWorkspace() + "/VSTART_HTML"); if (!hPath.exists()) { hPath.mkdirs(); } //Create file on workspace File htmlReportFile = new File( build.getWorkspace() + "/VSTART_HTML" + "/VSTART_REPORT_" + build.getNumber() + ".html"); if (!htmlReportFile.createNewFile()) { return false; } //append on file with fileWriter FileWriter fileWriter = new FileWriter(htmlReportFile, true); BufferedWriter wp = new BufferedWriter(fileWriter); StringBuilder builder = new StringBuilder(); //Begin document builder.append("<!DOCTYPE html>").append("\n"); builder.append("<html>").append("\n"); //Head builder.append("<head> " + "<meta charset='utf-8'>" + "<meta name='viewport' content='width=device-width, initial-scale=1'> " + "<link rel='stylesheet' href='" + Jenkins.getInstance().getRootUrl() + "/plugin/Vstart-Plugin/theme.min.css'>" + "<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js'></script>" + "<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js'></script>" + "<style type='text/css'>" + ".center {" + "margin: auto;" + "width: 60%;" + "border:0px;" + "padding: 10px;" + "}" + "h3{" + "font-family: inherit;" + "color: #1faf8e;" + "line-height: 1.1;" + "}" + ".FAILED{" + "color: red;" + "} " + ".PASSED{" + "color: #8ac007;" + "}" + "a#btn1 {" + "margin-top : 10px;" + "border: none;" + "}" + "</style> " + "<title>VSTART Report #" + build.getNumber() + "</title>" + "</head>") .append("\n"); //Body builder.append("<body>\n").append("\n"); //Button builder.append("<div class=\"container-fluid\">\n").append("\n"); builder.append("<div class='row'>\n").append("\n"); builder.append("<div class='col-md-3'>\n").append("\n"); builder.append("<a class=\"btn btn-primary\" href='" + build.getProject().getAbsoluteUrl() + "' id=\"btn1\">Back to Project</a>" + "</div>" + "</div>" + "</div>").append("\n"); //Structure builder.append("<div class=\"container-fluid\">\n").append("\n"); builder.append("<div class='row'>\n").append("\n"); //Main column builder.append( "<div class='col-md-9'style=\"\n" + " border-right: lightgray dashed 1px;\n" + "\">\n") .append("\n"); //Header builder.append("<div class=\"container-fluid\">\n").append("\n"); builder.append("<h1>VSTART Report #" + build.getNumber() + "</h1>").append("\n"); // builder.append("<p class='lead'>Started:" + build + "</p>").append("\n"); builder.append("<p class='lead'>Duration:" + build.getDurationString() + "</p>").append("\n"); builder.append("</div>\n").append("\n"); boolean isFirstTime = true; //Control graph ids to communicate with javascript for (int i = 0; i < jArrayReport.length(); i++) { //get testcase jsonobject report JSONObject jsonReport = jArrayReport.getJSONObject(i); builder.append(" <div class=\"container-fluid\">\n" + " <h2" + " id=\"testcase" + i + "\">" + "Test Case - " + jsonReport.getString("testCaseName") + "</h2>").append("\n"); //Graph Random rand = new Random(); int id = rand.nextInt(1000) + 1; builder.append("<div class= 'row'>" + "<div class='col-md-12'>" + "<div class='panel panel-default'>" + "<div class='panel-heading'> Test Case Execution Graph </div>" + "<div class='panel-body'>" + " <div id='graph" + id + "' style='/*display: block;*/ width: 100%; height: 600px;' class='center-block'></div>\n" + " </div> \n" + " </div> \n" + " </div> \n" + " </div> \n" + " </div> \n").append("\n"); builder.append(" <script type='text/javascript'>").append("\n"); //if this is the first testcase, the object array must be initialized if (isFirstTime) { //create object builder.append("obj = {}").append("\n"); //insert key and value builder.append("obj.graph" + id + " = " + new JSONObject(jsonReport.getString("extendedGraph")).toString()).append("\n"); //create array builder.append("var arr = []").append("\n"); //push to array builder.append("arr.push(obj)").append("\n"); //invert variable isFirstTime = false; } else { //create object builder.append("obj = {}").append("\n"); //insert key and value builder.append("obj.graph" + id + " = " + new JSONObject(jsonReport.getString("extendedGraph")).toString() + ";").append("\n"); //push to array builder.append("arr.push(obj);").append("\n"); } // builder.append("var graphId =").append(Integer.toString(id)).append(";").append("\n"); // builder.append("data=").append(new JSONObject(jsonReport.getString("extendedGraph")).toString()).append("\n"); builder.append("pathPrefix=").append(" '" + Jenkins.getInstance().getRootUrl()).append("' \n"); builder.append("</script>\n" + " <script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/cytoscape/2.4.6/cytoscape.js'></script>\n" + " <script type='text/javascript' src='" + Jenkins.getInstance().getRootUrl() + "/plugin/Vstart-Plugin/dagre.js'></script>\n" + " <script type='text/javascript' src='" + Jenkins.getInstance().getRootUrl() + "/plugin/Vstart-Plugin/DesignGraph.js'></script>\n" + " <script type='text/javascript' src='" + Jenkins.getInstance().getRootUrl() + "/plugin/Vstart-Plugin/app.js'></script>").append("\n"); //end of Graph //Table builder.append("<div class=\"container-fluid\">\n").append("\n"); builder.append("<div class=\"row\">\n").append("\n"); JSONArray jSteps = jsonReport.getJSONArray("steps"); for (int j = 0; j < jSteps.length(); j++) { JSONObject json = jSteps.getJSONObject(j); builder.append(" <div class='col-lg-6 col-md-12'>\n" + " <div class=\"panel panel-default\">\n" + " <div class='panel-heading' style='overflow: auto;'> ") .append("\n"); builder.append("<h3 " + "id='step" + i + j + "'>" + "Step #" + j + " : " + json.getString("scriptName").toString() + "</h3>" + "</div>").append("\n"); builder.append("<table class='table'> \n" + " <tbody>").append("\n"); //Script Language builder.append("<tr> \n" + " <td class='field-names'>Language: </td>" + "<td>" + json.getString("scriptLanguage").toString() + "</td>\n</tr>").append("\n"); //Test case status if (json.getString("status").equals("PASSED")) { builder.append(" <tr> \n" + " <td class='field-names'>Status: </td>\n" + " <td class='PASSED'>PASSED</td>\n" + " </tr>").append("\n"); } else if (json.getString("status").equals("FAILED")) { builder.append("<tr> \n" + " <td class='field-names'>Status: </td>\n" + " <td class='FAILED'>FAILED</td>\n" + " </tr>").append("\n"); } //Script source code builder.append("<tr> \n" + " <td class='field-names'> Source: </td>") .append("\n"); builder.append(" <td> \n" + " <pre>" + json.getString("scriptSource") + "</pre> \n" + " </td> \n" + " </tr>").append("\n"); //Expected Return Value builder.append("<tr> \n" + " <td class='field-names'>Return Value (Expected): </td>") .append("\n"); builder.append( " <td>" + json.getString("expectedValue").toString() + "</td>" + " </tr>") .append("\n"); //Print parameters table JSONObject jParam = json.getJSONObject("scriptParameters"); //Parameters JSONObject for iteration Iterator<?> keys = jParam.keys(); builder.append(" <td class='field-names'>Parameters: </td>\n" + " <td>\n" + " <table class='table table-striped'>\n" + " <tbody>").append("\n"); while (keys.hasNext()) { String key = (String) keys.next(); if (jParam.get(key) instanceof String) { builder.append("<tr>").append("\n"); builder.append("<td class='field-names'>").append("\n"); builder.append(key.toString()).append("</td>").append("\n"); builder.append("<td>").append("\n"); builder.append(jParam.get(key).toString()).append("</td>").append("\n"); builder.append("</tr>").append("\n"); } } builder.append("</tbody> \n </table> \n </td>").append("\n"); //Script Output builder.append(" <tr>\n" + " <td class=" + "'field-names'>Script Output: </td>").append("\n"); builder.append("<td><pre>" + json.getString("scriptOutput").toString() + "</pre>" + "</tr>\n") .append("\n"); //Actual return value builder.append(" <tr>\n" + " <td class='field-names'>Return Value (Actual): </td>" + " <td>" + json.getString("returnedValue").toString() + "</td>" + " </tr>").append("\n"); //Close element builder.append(" </tbody> \n" + " </table> \n" + " </div>\n" + " </div>").append("\n"); } builder.append(" </div>\n").append("\n"); builder.append(" </div>\n").append("\n"); //add testbed panel builder.append("<div class=\"container-fluid\">\n").append("\n"); builder.append("<div class=\"row\">\n").append("\n"); builder.append("<div class=\"col-md-12\">\n").append("\n"); builder.append("<div class='panel panel-default'>").append(""); builder.append("<div class='panel-heading' id='testbed" + i + "'> TESTBED </div>").append("\n"); builder.append("<table class='table table-hover table-striped machines'>").append("\n"); builder.append("<thead>").append("\n"); builder.append("<tr class='step-headers'>").append("\n"); builder.append("<th>Machine</th>").append("\n"); builder.append("<th>Label</th>").append("\n"); builder.append("</tr>").append("\n"); builder.append("<tbody>").append("\n"); //Loop through JSONObject JSONObject jTestBed = jsonReport.getJSONObject("testBed"); Iterator<?> testKeys = jTestBed.keys(); while (testKeys.hasNext()) { String key = (String) testKeys.next(); if (jTestBed.get(key) instanceof String) { builder.append("<tr>").append("\n"); builder.append("<td>").append("\n"); builder.append(key).append("</td>").append("\n"); builder.append("<td>").append("\n"); builder.append(jTestBed.get(key).toString()).append("</td>").append("\n"); builder.append("</tr>").append("\n"); } } builder.append("</tbody>").append("\n"); builder.append("</table>").append("\n"); builder.append("</div>").append("\n"); builder.append("</div>").append("\n"); builder.append("</div>").append("\n"); builder.append("</div>").append("\n"); } builder.append("</div>").append("\n"); builder.append("<div class='col-md-3'>").append("\n"); builder.append("<nav class='sidebar hidden-xs hidden-print hidden-sm affix'>").append("\n"); //links to testcase information builder.append("<h4>VSTART Report #" + build.getNumber() + "</h4>"); builder.append("<ul>").append("\n"); for (int c = 0; c < jArrayReport.length(); c++) { JSONObject jsonReport = jArrayReport.getJSONObject(c); builder.append("<li>").append("\n"); builder.append("<a href='#testcase" + c + "'>").append("\n"); builder.append("<b>").append("\n"); builder.append("Test Case: " + jsonReport.getString("testCaseName")).append("\n"); builder.append("</b>").append("\n"); builder.append("</a>").append("\n"); //Steps builder.append("<ul>").append("\n"); JSONArray jArray = jsonReport.getJSONArray("steps"); for (int d = 0; d < jArray.length(); d++) { builder.append("<li>").append("\n"); builder.append("<a href='#step" + c + d + "'>").append("\n"); builder.append("Step #" + d + ":" + jArray.getJSONObject(d).getString("scriptName")) .append("\n"); builder.append("</a>").append("\n"); builder.append("</li>").append("\n"); } //testbed builder.append("<li>").append("\n"); builder.append("<a href='#testbed" + c + "'>").append("\n"); builder.append("Testbed").append("\n"); builder.append("</a>").append("\n"); builder.append("</li>").append("\n"); builder.append("</ul>").append("\n"); builder.append("</li>").append("\n"); } builder.append("<li>").append("\n"); builder.append("<a href=\"" + build.getProject().getAbsoluteUrl() + "\"> Back to Project </a></li>") .append("\n"); builder.append(" </ul>").append("\n"); builder.append(" </nav>").append("\n"); builder.append(" </div>").append("\n"); //Finish document builder.append(" </div>\n" + " </div>\n" + "\n" + " </body>\n" + "</html>") .append("\n"); //Print to html file on project's workspace wp.write(builder.toString()); wp.close(); return true; } catch (IOException ex) { Logger.getLogger(VSPluginHtmlWriter.class.getName()).log(Level.SEVERE, null, ex); return false; } catch (InterruptedException ex) { Logger.getLogger(VSPluginHtmlWriter.class.getName()).log(Level.SEVERE, null, ex); return false; } }
From source file:siminov.web.reader.WebSiminovDataReader.java
private Object getValue(String name, JSONObject jsonObject) throws SiminovException { try {//from w w w .jav a 2s .com return jsonObject.get(name); } catch (Exception exception) { Log.error(WebSiminovDataReader.class.getName(), "", "Exception caught while getting value, " + exception.getMessage()); throw new SiminovException(WebSiminovDataReader.class.getName(), "", "Exception caught while getting value, " + exception.getMessage()); } }
From source file:com.voidsearch.data.provider.facebook.objects.PhotoEntry.java
public PhotoEntry(JSONObject data) throws Exception { super(data);// w ww . jav a2 s. c o m createdTime = (String) data.get("created_time"); updatedTime = (String) data.get("updated_time"); }