Java Code Examples for net.sf.json.JSONObject#keySet()
The following examples show how to use
net.sf.json.JSONObject#keySet() .
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: JsonTools.java From sso-oauth2 with Apache License 2.0 | 6 votes |
/** * * json转换map. * <br>详细说明 * @param jsonStr json字符串 * @return * @return Map<String,Object> 集合 * @throws * @author slj */ public static Map<String, Object> parseJSON2Map(String jsonStr) { ListOrderedMap map = new ListOrderedMap(); // System.out.println(jsonStr); // 最外层解析 JSONObject json = JSONObject.fromObject(jsonStr); for (Object k : json.keySet()) { Object v = json.get(k); // 如果内层还是数组的话,继续解析 if (v instanceof JSONArray) { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Iterator<JSONObject> it = ((JSONArray) v).iterator(); while (it.hasNext()) { JSONObject json2 = it.next(); list.add(parseJSON2Map(json2.toString())); } map.put(k.toString(), list); } else { map.put(k.toString(), v); } } return map; }
Example 2
Source File: JsonTools.java From sso-oauth2 with Apache License 2.0 | 6 votes |
/** * * json转换map. * <br>详细说明 * @param jsonStr json字符串 * @return * @return Map<String,Object> 集合 * @throws * @author slj */ public static Map<String, Object> parseJSON2Map(String jsonStr) { ListOrderedMap map = new ListOrderedMap(); // System.out.println(jsonStr); // 最外层解析 JSONObject json = JSONObject.fromObject(jsonStr); for (Object k : json.keySet()) { Object v = json.get(k); // 如果内层还是数组的话,继续解析 if (v instanceof JSONArray) { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Iterator<JSONObject> it = ((JSONArray) v).iterator(); while (it.hasNext()) { JSONObject json2 = it.next(); list.add(parseJSON2Map(json2.toString())); } map.put(k.toString(), list); } else { map.put(k.toString(), v); } } return map; }
Example 3
Source File: JiraClientSvcImpl.java From jira-ext-plugin with Apache License 2.0 | 5 votes |
@Override public Map<String, String> getJiraFields(String issueKey) throws JiraException { logger.fine("Get JIRA field ids for key: " + issueKey); Map<String, String> result = new HashMap<>(); JiraClient client = newJiraClient(); RestClient restClient = client.getRestClient(); try { JSONObject json = (JSONObject)restClient.get("/rest/api/latest/issue/" + issueKey); JSONObject fields = (JSONObject) json.get("fields"); for (Object key : fields.keySet()) { String fieldName = (String)key; String fieldValue = "null"; if (fields.get(fieldName) != null) { fieldValue = fields.get(fieldName).toString(); } result.put(fieldName, fieldValue); } return result; } catch (Throwable t) { throw new JiraException("Exception getting fields for JIRA issue", t); } }
Example 4
Source File: BuildResultProcessorTest.java From phabricator-jenkins-plugin with MIT License | 5 votes |
@Test public void testProcessLintViolations() throws Exception { String content = "{\"name\": \"Syntax Error\"," + "\"code\": \"EXAMPLE\"," + "\"severity\": \"error\"," + "\"path\": \"path/to/example\"," + "\"line\": 17," + "\"char\": 3}"; final LintResult result = new LintResult("Syntax Error", "EXAMPLE", "error", "path/to/example", 17, 3, ""); ConduitAPIClient conduitAPIClient = new ConduitAPIClient(null, null) { @Override public JSONObject perform(String action, JSONObject params) throws IOException, ConduitAPIException { if (action == "harbormaster.sendmessage") { JSONObject json = (JSONObject) ((JSONArray) params.get("lint")).get(0); JSONObject parsed = result.toHarbormaster(); assertNotNull(parsed); assertNotNull(json); for (String key : (Set<String>) params.keySet()) { assertEquals("mismatch in expected json key: " + key, parsed.get(key), json.get(key)); } return result.toHarbormaster(); } return new JSONObject(); } }; runProcessLintViolationsTest(content, conduitAPIClient); }
Example 5
Source File: GangliaMetricService.java From Hue-Ctrip-DI with MIT License | 5 votes |
@SuppressWarnings("unchecked") private synchronized void initClusterInfo(boolean force) { if (clusterHostsMap.isEmpty() || metricMap.isEmpty() || force) { String json = UrlUtils.getContent(hostUrl); JSONObject jsonObject = JSONObject.fromObject(json); JSONObject messagejson = (JSONObject) jsonObject.get("message"); JSONObject clustersJson = (JSONObject) messagejson.get("clusters"); for (String cluster : (Set<String>) clustersJson.keySet()) { try { JSONArray hostArray = (JSONArray) clustersJson.get(cluster); List<String> hostList = new ArrayList<String>(); Iterator<String> iterator = hostArray.iterator(); while (iterator.hasNext()) { String host = iterator.next(); hostList.add(host); } if (hostList.size() != 0) { clusterHostsMap.put(cluster, hostList); } List<String> metricList = httpParser .getGangliaAttribute(cluster); if (metricList != null && metricList.size() != 0) { metricMap.put(cluster, metricList); } } catch (Exception e) { logger.error("Ganglia Http Parser Error", e); throw new RuntimeException("Ganglia Http Parser Error", e); } } } }
Example 6
Source File: TestGangliaMetricService.java From Hue-Ctrip-DI with MIT License | 5 votes |
public static void main(String[] args) { String json = UrlUtils .getContent("http://10.8.75.3/ganglia/?r=hour&cs=&ce=&s=by+name&c=Hbase_Dashboard_Cluster&tab=m&vn=&hide-hf=false"); JSONObject jsonObject = JSONObject.fromObject(json); JSONObject messagejson = (JSONObject) jsonObject.get("message"); JSONObject clustersJson = (JSONObject) messagejson.get("clusters"); @SuppressWarnings("unchecked") Set<String> test = clustersJson.keySet(); for (String cluster : test) { System.out.println(cluster); } }
Example 7
Source File: JsonUtil.java From zxl with Apache License 2.0 | 5 votes |
public static void copyToBean(JSONObject jsonObject, Object bean) throws SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (bean == null || jsonObject == null) { throw new NullPointerException("jsonObject:" + jsonObject + " bean:" + bean); } Class<?> clazz = bean.getClass(); for (Object key : jsonObject.keySet()) { try { Field field = clazz.getDeclaredField(key.toString()); ReflectUtil.setFieldValue(bean, field, jsonObject.get(key)); } catch (NoSuchFieldException e) { LogUtil.warn(LOGGER, "copyToBean未找到该属性:" + key.toString()); continue; } } }
Example 8
Source File: MetadataResource.java From oodt with Apache License 2.0 | 5 votes |
private Metadata getMetadataFromJSON(String metadataJSON) { JSONObject json = (JSONObject) JSONSerializer.toJSON(metadataJSON); Metadata metadata = new Metadata(); Set<String> keys = json.keySet(); for (String key : keys) { List values = (List) JSONSerializer.toJava((JSONArray) json.get(key)); metadata.addMetadata(key, values); } return metadata; }
Example 9
Source File: Restore.java From mobi with GNU Affero General Public License v3.0 | 4 votes |
private void restoreRepositories(JSONObject manifest, String backupVersion) throws IOException { // Clear populated repositories Set<String> remoteRepos = new HashSet<>(); repositoryManager.getAllRepositories().forEach((repoID, repo) -> { if (repo.getConfig() instanceof NativeRepositoryConfig || repo.getConfig() instanceof MemoryRepositoryConfig) { try (RepositoryConnection connection = repo.getConnection()) { connection.clear(); } } else { remoteRepos.add(repoID); } }); // Populate Repositories JSONObject repos = manifest.optJSONObject("repositories"); ImportServiceConfig.Builder builder = new ImportServiceConfig.Builder() .continueOnError(false) .logOutput(true) .printOutput(true) .batchSize(batchSize); for (Object key : repos.keySet()) { String repoName = key.toString(); if (!remoteRepos.contains(repoName)) { String repoPath = repos.optString(key.toString()); String repoDirectoryPath = repoPath.substring(0, repoPath.lastIndexOf(repoName + ".zip")); builder.repository(repoName); File repoFile = new File(RESTORE_PATH + File.separator + repoDirectoryPath + File.separator + repoName + ".trig"); importService.importFile(builder.build(), repoFile); LOGGER.trace("Data successfully loaded to " + repoName + " repository."); System.out.println("Data successfully loaded to " + repoName + " repository."); } else { LOGGER.trace("Skipping data load of remote repository " + repoName); System.out.println("Skipping data load of remote repository " + repoName); } } // Remove Policy Statements RepositoryConnection conn = config.getRepository().getConnection(); Iterator<Statement> statements = conn.getStatements(null, vf.createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), vf.createIRI(PolicyFile.TYPE)) .iterator(); while (statements.hasNext()) { conn.clear(statements.next().getSubject()); } LOGGER.trace("Removed PolicyFile statements"); if (mobiVersions.indexOf(backupVersion) < 2) { // Clear ontology editor state statements = conn.getStatements(null, vf.createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), vf.createIRI(State.TYPE)).iterator(); while (statements.hasNext()) { stateManager.deleteState(statements.next().getSubject()); } LOGGER.trace("Remove state statements"); } }
Example 10
Source File: Twilio.java From BotLibre with Eclipse Public License 1.0 | 4 votes |
/** * Generate the voice Twilio TwiML XML string from the reply and command JSON. */ public String generateVoiceTwiML(String command, String reply) { JSONObject json = null; if (command != null && !command.isEmpty()) { JSONObject root = (JSONObject)JSONSerializer.toJSON(command); json = root.optJSONObject("twiml"); } StringWriter writer = new StringWriter(); writer.write("<Response>"); if (json == null) { writer.write("<Gather timeout='3' input='speech dtmf'>"); writer.write("<Say>" + reply + "</Say>"); writer.write("</Gather>"); writer.write("</Response>"); return writer.toString(); } // If there is a command, then only write the command elements. // Append the reply to the gather. boolean hasSay = false; for (Object key : json.keySet()) { boolean isGather = "Gather".equals(String.valueOf(key)); boolean isSay = "Say".equals(String.valueOf(key)); writer.write("<"); writer.write(String.valueOf(key)); Object element = json.opt((String)key); if (element instanceof String) { writer.write(">"); writer.write(String.valueOf(element)); } else if (element instanceof JSONObject) { boolean hasInput = false; boolean hasTimeout = false; for (Object attribute : ((JSONObject)element).keySet()) { if ("input".equals(String.valueOf(attribute))) { hasInput = true; } if ("timeout".equals(String.valueOf(attribute))) { hasTimeout = true; } writer.write(" "); writer.write(String.valueOf(attribute)); writer.write("='"); Object value = ((JSONObject)element).opt((String)attribute); writer.write(String.valueOf(value)); writer.write("'"); } if (!hasInput && isGather) { writer.write(" input='speech dtmf'"); } if (!hasTimeout && isGather) { writer.write(" timeout='3'"); } writer.write(">"); if (isSay) { writer.write(reply); hasSay = true; } } if (isGather && !hasSay) { writer.write("<Say>" + reply + "</Say>"); } writer.write("</"); writer.write(String.valueOf(key)); writer.write(">"); } writer.write("</Response>"); return writer.toString(); }
Example 11
Source File: Family.java From zxl with Apache License 2.0 | 4 votes |
public void putJsonObject(JSONObject object){ for (Object key : object.keySet()) { this.object.put(key.toString(), object.get(key).toString()); } }