Java Code Examples for net.sf.json.JSONArray#getJSONObject()
The following examples show how to use
net.sf.json.JSONArray#getJSONObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Awvs.java From TrackRay with GNU General Public License v3.0 | 6 votes |
public List<Target> targets(){ JSONObject obj = targetsJSON(); List <Target> list = new ArrayList<>(); if (obj.containsKey("targets")){ JSONArray scans = obj.getJSONArray("targets"); for (int i = 0; i < scans.size(); i++) { JSONObject scan = scans.getJSONObject(i); try { Target s = this.toBean(scan.toString(), Target. class); list.add(s); } catch (IOException e) { continue; } } } return list; }
Example 2
Source File: KunpengScan.java From TrackRay with GNU General Public License v3.0 | 6 votes |
private void loadPlugins() { String result = Kunpeng.INSTANCE.GetPlugins(); result = Native.toString(Native.toByteArray(result), "UTF-8"); targets.clear(); plugins.clear(); JSONArray arr = toJSON(result); if (arr!=null && !arr.isEmpty()){ for (int i = 0; i < arr.size(); i++) { JSONObject obj = arr.getJSONObject(i); String name = obj.getString("name"); String remarks = obj.getString("remarks"); String target = obj.getString("target"); String type = obj.getString("type"); Plugin plugin = new Plugin(); plugin.setName(name); plugin.setRemarks(remarks); plugin.setTarget(target); plugin.setType(type); targets.add(target); plugins.add(plugin); } } }
Example 3
Source File: ParallelsDesktopConnectorSlaveComputer.java From jenkins-parallels with MIT License | 6 votes |
private String getVmIPAddress(String vmId) throws Exception { int TIMEOUT = 60; for (int i = 0; i < TIMEOUT; ++i) { RunVmCallable command = new RunVmCallable("list", "-f", "--json", vmId); String callResult = forceGetChannel().call(command); LOGGER.log(Level.SEVERE, " - (" + i + "/" + TIMEOUT + ") calling for IP"); LOGGER.log(Level.SEVERE, callResult); JSONArray vms = (JSONArray)JSONSerializer.toJSON(callResult); JSONObject vmInfo = vms.getJSONObject(0); String ip = vmInfo.getString("ip_configured"); if (!ip.equals("-")) return ip; Thread.sleep(1000); } throw new Exception("Failed to get IP for VM '" + vmId + "'"); }
Example 4
Source File: Engine.java From acunetix-plugin with MIT License | 6 votes |
public String getTargetName(String targetId) throws IOException { JSONArray targets = getTargets(); for (int i = 0; i < targets.size(); i++) { JSONObject item = targets.getJSONObject(i); String target_id = item.getString("target_id"); if (target_id.equals(targetId)) { String address = item.getString("address"); String description = item.getString("description"); String target_name = address; if (description.length() > 0) { if (description.length() > 100) { description = description.substring(0, 100); } target_name += " (" + description + ")"; } return target_name; } } return null; }
Example 5
Source File: MergeRequestRestTest.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Test public void getMergeRequestsTest() { Response response = target().path("merge-requests").request().get(); assertEquals(response.getStatus(), 200); verify(requestManager).getMergeRequests(any(MergeRequestFilterParams.class)); try { JSONArray result = JSONArray.fromObject(response.readEntity(String.class)); assertEquals(result.size(), 1); JSONObject requestObj = result.getJSONObject(0); assertFalse(requestObj.containsKey("@graph")); assertTrue(requestObj.containsKey("@id")); assertEquals(requestObj.getString("@id"), request1.getResource().stringValue()); } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }
Example 6
Source File: BuildScanner.java From acunetix-plugin with MIT License | 6 votes |
public ListBoxModel doFillRepTempItems() throws IOException { ListBoxModel items = new ListBoxModel(); Engine apio = new Engine(gApiUrl, getgApiKey()); JSONArray jsa = apio.getReportTemplates(); items.add("Do not generate a report", "no_report"); for (int i = 0; i < jsa.size(); i++) { JSONObject item = jsa.getJSONObject(i); String group = item.getString("group"); String reportTemplate_name = item.getString("name"); String template_id = item.getString("template_id"); if (!reportTemplate_name.equals("Scan Comparison")) { items.add(reportTemplate_name, template_id); } } return items; }
Example 7
Source File: BuildScanner.java From acunetix-plugin with MIT License | 6 votes |
public ListBoxModel doFillTargetItems() throws IOException { ListBoxModel items = new ListBoxModel(); Engine apio = new Engine(gApiUrl, getgApiKey()); JSONArray jsa = apio.getTargets(); for (int i = 0; i < jsa.size(); i++) { JSONObject item = jsa.getJSONObject(i); String mi = item.getString("manual_intervention"); if (mi.equals("null") || mi.equals("false")) { String address = item.getString("address"); String target_id = item.getString("target_id"); String description = item.getString("description"); String target_name = address; if (description.length() > 0) { if (description.length() > 100) { description = description.substring(0, 100); } target_name += " (" + description + ")"; } items.add(target_name, target_id); } } return items; }
Example 8
Source File: WorkflowServiceImpl.java From studio with GNU General Public License v3.0 | 6 votes |
/** * get submitted items from JSON request * * @param site * @param items * @param format * @return submitted items * @throws JSONException */ protected List<DmDependencyTO> getSubmittedItems(String site, JSONArray items, SimpleDateFormat format, String schDate) throws JSONException, ServiceLayerException { if (items != null) { int length = items.size(); if (length > 0) { List<DmDependencyTO> submittedItems = new ArrayList<>(); for (int index = 0; index < length; index++) { JSONObject item = items.getJSONObject(index); DmDependencyTO submittedItem = getSubmittedItem(site, item, format, schDate); submittedItems.add(submittedItem); } return submittedItems; } } return null; }
Example 9
Source File: Engine.java From acunetix-plugin with MIT License | 5 votes |
public String getReportTemplateName(String reportTemplateId) throws IOException { JSONArray jsa = getReportTemplates(); for (int i = 0; i < jsa.size(); i++) { JSONObject item = jsa.getJSONObject(i); if (item.getString("template_id").equals(reportTemplateId)) { return item.getString("name"); } } return null; }
Example 10
Source File: ContentReviewServiceTurnitinOC.java From sakai with Educational Community License v2.0 | 5 votes |
public ArrayList<Webhook> getWebhooks() throws Exception { ArrayList<Webhook> webhooks = new ArrayList<>(); HashMap<String, Object> response = makeHttpCall("GET", getNormalizedServiceUrl() + "webhooks", BASE_HEADERS, null, null); // Get response: int responseCode = !response.containsKey(RESPONSE_CODE) ? 0 : (int) response.get(RESPONSE_CODE); String responseMessage = !response.containsKey(RESPONSE_MESSAGE) ? "" : (String) response.get(RESPONSE_MESSAGE); String responseBody = !response.containsKey(RESPONSE_BODY) ? "" : (String) response.get(RESPONSE_BODY); if(StringUtils.isNotEmpty(responseBody) && responseCode >= 200 && responseCode < 300 && !"[]".equals(responseBody)) { // Loop through response via JSON, convert objects to Webhooks JSONArray webhookList = JSONArray.fromObject(responseBody); for (int i=0; i < webhookList.size(); i++) { JSONObject webhookJSON = webhookList.getJSONObject(i); if (webhookJSON.has("id") && webhookJSON.has("url")) { webhooks.add(new Webhook(webhookJSON.getString("id"), webhookJSON.getString("url"))); } } }else { log.info("getWebhooks: " + responseMessage); } return webhooks; }
Example 11
Source File: BuildScanner.java From acunetix-plugin with MIT License | 5 votes |
public ListBoxModel doFillProfileItems() throws IOException { ListBoxModel items = new ListBoxModel(); Engine apio = new Engine(gApiUrl, getgApiKey()); JSONArray jsa = apio.getScanningProfiles(); for (int i = 0; i < jsa.size(); i++) { JSONObject item = jsa.getJSONObject(i); String profile_name = item.getString("name"); String profile_id = item.getString("profile_id"); items.add(profile_name, profile_id); } return items; }
Example 12
Source File: JSONConverterTest.java From jmeter-bzm-plugins with Apache License 2.0 | 5 votes |
private void assertAssertions(JSONObject label) { JSONArray assertions = label.getJSONArray("assertions"); assertEquals(1, assertions.size()); JSONObject jsonObject = assertions.getJSONObject(0); assertEquals("1", jsonObject.getString("failures")); assertEquals("All Assertions", jsonObject.getString("name")); assertEquals("assertion failed", jsonObject.getString("failureMessage")); }
Example 13
Source File: IdentityAction.java From anychat with MIT License | 5 votes |
/** * 获取好友列表相当于组里的所有人 * * @param userGroupTopId * 组id * @param token * 身份 * @return */ public static List<UserData> getFriendList(String userGroupTopId, String token) { JSONObject js = new JSONObject(); js.put("hOpCode", "13"); js.put("userGroupTopId", userGroupTopId); Map<String, String> header = new HashMap<>(); header.put("hOpCode", "13"); header.put("token", token); byte[] returnByte = HttpUtil.send(js.toString(), CommonConfigChat.IDENTITY_URL, header, HttpUtil.POST); if (returnByte != null) { String str = null; try { str = new String(returnByte, "UTF-8"); } catch (UnsupportedEncodingException e) { WSManager.log.error("返回字符串解析异常", e); } JSONObject returnjs = JSONObject.fromObject(str); // 如果返回的是错误类型,说明用户中心拦截器没通过 if (returnjs.getString("hOpCode").equals("0")) { return null; } JSONArray jsArray = returnjs.getJSONArray("user"); List<UserData> list = new ArrayList<>(); for (int i = 0; i < jsArray.size(); i++) { JSONObject user = jsArray.getJSONObject(i); UserData userData = new UserData(user); list.add(userData); } return list; } return null; }
Example 14
Source File: FormUtil.java From jeecg with Apache License 2.0 | 5 votes |
private static String GetRadios(JSONObject item, Map<String, Object> formData, String action) { JSONArray radiosOptions = item.getJSONArray("options"); // JArray radiosOptions = item["options"] as JArray; String temp = "<input type=\"radio\" name=\"{0}\" value=\"{1}\" {2}>{3} "; String temp_html = ""; String name = item.getString("name").toString(); String value = formData.get(name) == null ? null : formData.get(name) .toString(); String cvalue_ = ""; for (int f = 0; f < radiosOptions.size(); f++) { JSONObject json = radiosOptions.getJSONObject(f);// 获取对象 String cvalue = json.getString("value").toString(); String Ischecked = ""; if (value == null) { String check = (json.has("checked") && json .getString("checked") != null) ? json.getString( "checked").toString() : ""; if ("checked".equals(check) || "true".equals(check)) { Ischecked = " checked=\"checked\" "; cvalue_ = cvalue; } } temp_html += MessageFormat.format(temp, name, cvalue, Ischecked, cvalue); } if ("view".equals(action)) return MessageFormat.format(temp_view, " ", cvalue_); else return temp_html; }
Example 15
Source File: CommitRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void getCommitHistoryWithEntityNoTargetTest() { when(catalogManager.getCommitEntityChain(any(Resource.class), any(Resource.class))).thenReturn(entityCommits); Response response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/history") .queryParam("entityId", encode(vf.createIRI("http://mobi.com/test/class5"))) .queryParam("offset", 0) .queryParam("limit", 1) .request().get(); assertEquals(response.getStatus(), 200); verify(catalogManager).getCommitEntityChain(vf.createIRI(COMMIT_IRIS[1]), vf.createIRI("http://mobi.com/test/class5")); MultivaluedMap<String, Object> headers = response.getHeaders(); assertEquals(headers.get("X-Total-Count").get(0), "" + ENTITY_IRI.length); assertEquals(response.getLinks().size(), 0); Set<Link> links = response.getLinks(); assertEquals(links.size(), 0); links.forEach(link -> { assertTrue(link.getUri().getRawPath().contains("commits/" + encode(COMMIT_IRIS[1]) + "/history")); assertTrue(link.getRel().equals("prev") || link.getRel().equals("next")); }); try { JSONArray result = JSONArray.fromObject(response.readEntity(String.class)); assertEquals(result.size(), 1); JSONObject commitObj = result.getJSONObject(0); assertTrue(commitObj.containsKey("id")); assertEquals(commitObj.getString("id"), COMMIT_IRIS[1]); } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }
Example 16
Source File: ContentReviewServiceTurnitinOC.java From sakai with Educational Community License v2.0 | 5 votes |
public ArrayList<Webhook> getWebhooks() throws Exception { ArrayList<Webhook> webhooks = new ArrayList<>(); HashMap<String, Object> response = makeHttpCall("GET", getNormalizedServiceUrl() + "webhooks", BASE_HEADERS, null, null); // Get response: int responseCode = !response.containsKey(RESPONSE_CODE) ? 0 : (int) response.get(RESPONSE_CODE); String responseMessage = !response.containsKey(RESPONSE_MESSAGE) ? "" : (String) response.get(RESPONSE_MESSAGE); String responseBody = !response.containsKey(RESPONSE_BODY) ? "" : (String) response.get(RESPONSE_BODY); if(StringUtils.isNotEmpty(responseBody) && responseCode >= 200 && responseCode < 300 && !"[]".equals(responseBody)) { // Loop through response via JSON, convert objects to Webhooks JSONArray webhookList = JSONArray.fromObject(responseBody); for (int i=0; i < webhookList.size(); i++) { JSONObject webhookJSON = webhookList.getJSONObject(i); if (webhookJSON.has("id") && webhookJSON.has("url")) { webhooks.add(new Webhook(webhookJSON.getString("id"), webhookJSON.getString("url"))); } } }else { log.info("getWebhooks: " + responseMessage); } return webhooks; }
Example 17
Source File: FormUtil.java From jeecg with Apache License 2.0 | 4 votes |
/** * 解析后的html * @param parseHtml 替换过控件的html * @param contentData 控件信息json数组 * @param action view * @return */ public static String GetHtml(String parseHtml, String contentData, String action) { // action=action!=null && !"".equals(action)?action:"view"; Map<String, Object> tableData = new HashMap<String, Object>();// 表单数据 String html = parseHtml; JSONArray jsonArray = new JSONArray().fromObject(contentData); for (int f = 0; f < jsonArray.size(); f++) { if (jsonArray.getJSONObject(f) == null || "".equals(jsonArray.getJSONObject(f))) continue; JSONObject json = jsonArray.getJSONObject(f);// 获取对象 String name = ""; if(json==null){continue; } String leipiplugins = json.getString("leipiplugins").toString(); if ("checkboxs".equals(leipiplugins)) name = json.getString("parse_name").toString(); else name = json.getString("name").toString(); String temp_html = ""; if ("text".equals(leipiplugins)) { temp_html = GetTextBox(json, tableData, action); } else if ("textarea".equals(leipiplugins)) { temp_html = GetTextArea(json, tableData, action); } else if ("radios".equals(leipiplugins)) { temp_html = GetRadios(json, tableData, action); } else if ("select".equals(leipiplugins)) { temp_html = GetSelect(json, tableData, action); } else if ("checkboxs".equals(leipiplugins)) { temp_html = GetCheckboxs(json, tableData, action); } else if ("macros".equals(leipiplugins)) { temp_html = GetMacros(json, tableData, action); } else if ("qrcode".equals(leipiplugins)) { temp_html = GetQrcode(json, tableData, action); } else if ("listctrl".equals(leipiplugins)) { temp_html = GetListctrl(json, tableData, action); } else if ("progressbar".equals(leipiplugins)) { // case ""://进度条 (未做处理) /* temp_html = GetProgressbar(json, tableData, action); */ temp_html = json.getString("content").toString(); }else if ("popup".equals(leipiplugins)) { temp_html = GetPopUp(json, tableData, action); } else { temp_html = json.getString("content").toString(); } html = html.replace("{" + name + "}", temp_html); } return html; }
Example 18
Source File: GoogleServiceImpl.java From albert with MIT License | 4 votes |
public List<GoogleSearchResult> search(String searchKey) throws ClientProtocolException, IOException{ List<GoogleSearchResult> list= new ArrayList<>(); StringBuffer sb = new StringBuffer(); HttpClient client = ProxyUtil.getHttpClient(); // client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8"); HttpGet httpGet = new HttpGet(Constants.GOOGLE_SEARCH_URL+searchKey); HttpResponse response = client.execute(httpGet); Header[] headers = response.getAllHeaders(); if(200!=response.getStatusLine().getStatusCode()){ System.out.println("无法访问"); } HttpEntity entry = response.getEntity(); if(entry != null) { InputStreamReader is = new InputStreamReader(entry.getContent(),"UTF-8"); BufferedReader br = new BufferedReader(is); String str = null; while((str = br.readLine()) != null) { sb.append(str.trim()); } br.close(); } JSONArray jsonArray = null; JSONObject jsonObject=null; JSONObject itemsObject = null; // log.info(sb.toString()); itemsObject = JSONObject.fromObject(sb.toString()); if(!itemsObject.containsKey("items")){ log.info("没有查询结果"); return null; } jsonArray = itemsObject.getJSONArray("items"); GoogleSearchResult googleSearchResult =null; for(int i=0,length=jsonArray.size();i<length;i++){ googleSearchResult =new GoogleSearchResult(); jsonObject = jsonArray.getJSONObject(i); googleSearchResult.setFormattedUrl(jsonObject.getString("formattedUrl")); googleSearchResult.setHtmlTitle(jsonObject.getString("htmlTitle")); googleSearchResult.setLink(jsonObject.getString("link")); googleSearchResult.setHtmlSnippet(jsonObject.getString("htmlSnippet")); if(jsonObject.containsKey("pagemap")&&jsonObject.getJSONObject("pagemap").containsKey("cse_thumbnail")){ googleSearchResult.setSrc(jsonObject.getJSONObject("pagemap").getJSONArray("cse_thumbnail").getJSONObject(0).getString("src")); googleSearchResult.setWidth(jsonObject.getJSONObject("pagemap").getJSONArray("cse_thumbnail").getJSONObject(0).getString("width")); googleSearchResult.setHeight(jsonObject.getJSONObject("pagemap").getJSONArray("cse_thumbnail").getJSONObject(0).getString("height")); } list.add(googleSearchResult); } return list; }
Example 19
Source File: HiddenFilesScanRule.java From zap-extensions with Apache License 2.0 | 4 votes |
private List<HiddenFile> readFromJsonFile() { String jsonTxt = readPayloadsFile(); if (jsonTxt.isEmpty()) { return new ArrayList<>(); } try { JSONObject json = (JSONObject) JSONSerializer.toJSON(jsonTxt); JSONArray files = json.getJSONArray("files"); List<HiddenFile> hiddenFiles = new ArrayList<>(); for (int i = 0; i < files.size(); i++) { JSONObject hiddenFileObject = files.getJSONObject(i); HiddenFile hiddenFile = new HiddenFile( hiddenFileObject.getString("path"), getOptionalList(hiddenFileObject, "content"), getOptionalList(hiddenFileObject, "not_content"), getOptionalString(hiddenFileObject, "binary"), getOptionalList(hiddenFileObject, "links"), getOptionalString(hiddenFileObject, "type")); hiddenFiles.add(hiddenFile); if (LOG.isDebugEnabled()) { LOG.debug( "File to be located: " + hiddenFile.getPath() + " Content: " + hiddenFile.getContent()); } } return hiddenFiles; } catch (JSONException jEx) { LOG.warn( "Failed to parse " + getName() + " payloads file due to JSON parsing issue. " + jEx.getMessage(), jEx); return new ArrayList<>(); } }
Example 20
Source File: Config.java From pdf-extract with GNU General Public License v3.0 | 4 votes |
private void load() throws Exception { if (!common.IsExist(_path)) { return; } String sConfig = common.readFile(_path); if (common.IsEmpty(sConfig)) { return; } JSONObject json = common.getJSONFormat(sConfig); JSONArray languages = common.getJSONArray(json, "language"); _config = new ConfigInfo(); String sentenceJoinScript = common.getJSONValue(json, "script", "sentence_join"); _config.sentenceJoinScript = sentenceJoinScript; for (int i = 0, len = languages.size(); i < len; i++) { JSONObject config = languages.getJSONObject(i); String lang = common.getJSONValue(config, "name"); JSONObject langConfigs = common.getJSONObject(config, "config"); JSONArray joinWords = common.getJSONArray(langConfigs, "join_words"); JSONArray absoluteEOF = common.getJSONArray(langConfigs, "absolute_eof"); JSONArray normalize = common.getJSONArray(langConfigs, "normalize"); JSONArray repair = common.getJSONArray(langConfigs, "repair"); String sentenceJoinModel = common.getJSONValue(langConfigs, "sentencejoin_model"); LangInfo langInfo = new LangInfo(); langInfo.language = lang; langInfo.joinWords.addAll(getJoinWordsList(joinWords)); langInfo.absoluteEOF.addAll(getEOFList(absoluteEOF)); langInfo.normalize.addAll(getNormalizeList(normalize)); langInfo.repair.addAll(getNormalizeList(repair)); langInfo.sentenceJoinModel = sentenceJoinModel; _config.langConfig.put(lang, langInfo); } }