List of usage examples for org.json.simple JSONObject keySet
Set<K> keySet();
From source file:org.kawanfw.sql.json.JsonColPosition.java
/** * Format from JSON string Map<String, Integer> of (column name, column * position) of a result set//from w ww . j a v a 2 s . c om * * @param jsonString * formated JSON string containing the Map<String, Integer> of * (column name, column position) * @return Map<String, Integer> of (column name, column position) */ public static Map<String, Integer> fromJson(String jsonString) { if (jsonString == null) { throw new IllegalArgumentException("jsonString is null!"); } jsonString = HtmlConverter.fromHtml(jsonString); // Revert it Object obj = JSONValue.parse(jsonString); JSONObject mapBack = (JSONObject) obj; debug("jsonString : " + jsonString); debug("mapBack.toString(): " + mapBack.toString()); Map<String, Integer> columnPositions = new LinkedHashMap<String, Integer>(); Set<?> set = mapBack.keySet(); for (Iterator<?> iterator = set.iterator(); iterator.hasNext();) { String key = (String) iterator.next(); long value = (Long) mapBack.get(key); columnPositions.put(key, (int) value); } // free objects obj = null; mapBack = null; return columnPositions; }
From source file:org.kawanfw.sql.json.no_obfuscation.CallableStatementHolderTransportJsonSimple.java
/** * Convert from a Json string a List of StatementHolder * /*from ww w .j av a2 s . c om*/ * @return the StatementHolder list converted from Json */ @SuppressWarnings({ "rawtypes" }) public static CallableStatementHolder fromJson(String jsonString) { // Revert it Object obj = JSONValue.parse(jsonString); JSONObject mapBack = (JSONObject) obj; String sql = (String) mapBack.get("sql"); String stPstr = (String) mapBack.get("stP"); String parmsTstr = (String) mapBack.get("parmsT"); String parmsVstr = (String) mapBack.get("parmsV"); String outPstr = (String) mapBack.get("outP"); Boolean paramatersEncrypted = (Boolean) mapBack.get("paramatersEncrypted"); Boolean htmlEncodingOn = (Boolean) mapBack.get("htmlEncodingOn"); mapBack = null; Object objParmsT = JSONValue.parse(parmsTstr); JSONObject mapBackParmsT = (JSONObject) objParmsT; Object objParmsV = JSONValue.parse(parmsVstr); JSONObject mapBackParmsV = (JSONObject) objParmsV; Object JSONArray = JSONValue.parse(stPstr); JSONArray arrayBackStP = (JSONArray) JSONArray; Object outPstrT = JSONValue.parse(outPstr); JSONArray arrayBackoutP = (JSONArray) outPstrT; int[] stP = new int[StaParms.NUM_PARMS]; for (int i = 0; i < arrayBackStP.size(); i++) { long myLong = (Long) arrayBackStP.get(i); stP[i] = (int) myLong; } Map<Integer, Integer> parmsT = new TreeMap<Integer, Integer>(); Set set = mapBackParmsT.keySet(); for (Iterator iterator = set.iterator(); iterator.hasNext();) { String key = (String) iterator.next(); long value = (Long) mapBackParmsT.get(key); parmsT.put(Integer.parseInt(key), (int) value); } Map<Integer, String> parmsV = new TreeMap<Integer, String>(); set = mapBackParmsV.keySet(); for (Iterator iterator = set.iterator(); iterator.hasNext();) { String key = (String) iterator.next(); String value = (String) mapBackParmsV.get(key); parmsV.put(Integer.parseInt(key), value); } List<Integer> outP = new ArrayList<Integer>(); for (int i = 0; i < arrayBackoutP.size(); i++) { long myLong = (Long) arrayBackoutP.get(i); outP.add((int) myLong); } // Clean all to release memory for GC obj = null; objParmsT = null; objParmsV = null; arrayBackStP = null; arrayBackoutP = null; if (DEBUG) { String stPaString = "["; for (int i = 0; i < stP.length; i++) { stPaString += stP[i] + " "; } stPaString += "]"; System.out.println(); System.out.println(sql); System.out.println(stPaString); System.out.println(parmsT); System.out.println(parmsV); System.out.println(outP); System.out.println(paramatersEncrypted); System.out.println(htmlEncodingOn); System.out.println(); } CallableStatementHolder callableStatementHolder = new CallableStatementHolder(); callableStatementHolder.setSql(sql); callableStatementHolder.setStP(stP); callableStatementHolder.setParmsT(parmsT); callableStatementHolder.setParmsV(parmsV); callableStatementHolder.setOutP(outP); callableStatementHolder.setParamatersEncrypted(paramatersEncrypted); callableStatementHolder.setHtmlEncodingOn(htmlEncodingOn); return callableStatementHolder; }
From source file:org.ldaptive.io.JsonReader.java
/** * Reads JSON data from the reader and returns a search result. * * @return search result derived from the JSON * * @throws IOException if an error occurs using the reader *//*from ww w .j a v a 2 s .c o m*/ @Override @SuppressWarnings("unchecked") public SearchResult read() throws IOException { final SearchResult result = new SearchResult(sortBehavior); try { final JSONParser parser = new JSONParser(); final JSONArray jsonArray = (JSONArray) parser.parse(jsonReader); for (Object o : jsonArray) { final LdapEntry entry = new LdapEntry(sortBehavior); final JSONObject jsonObject = (JSONObject) o; for (Object k : jsonObject.keySet()) { final String attrName = (String) k; if ("dn".equalsIgnoreCase(attrName)) { entry.setDn((String) jsonObject.get(k)); } else { final LdapAttribute attr = new LdapAttribute(sortBehavior); attr.setName(attrName); attr.addStringValues((List<String>) jsonObject.get(k)); entry.addAttribute(attr); } } result.addEntry(entry); } } catch (ParseException e) { throw new IOException(e); } return result; }
From source file:org.murygin.neo4j.CypherToJGraphT.java
@SuppressWarnings("rawtypes") private void addProperties(IPropertyContainer node, JSONObject nodeJson) { JSONObject properties = JsonResults.getJson(nodeJson, "properties"); Set keys = properties.keySet(); for (Object keyObject : keys) { String key = (String) keyObject; String value = (String) properties.get(key); node.addProperty(key, value);//from w w w .j ava2 s .c o m if (LOG.isDebugEnabled()) { LOG.debug("Property added: " + key + ":" + value); } } }
From source file:org.neo4j.gis.spatial.indexfilter.DynamicIndexReader.java
private boolean queryNodeProperties(Node node, JSONObject properties) { if (properties != null) { if (properties.containsKey("geometry")) { System.out.println("Unexpected 'geometry' in query string"); properties.remove("geometry"); }/*ww w .ja va2 s . c om*/ for (Object key : properties.keySet()) { Object value = node.getProperty(key.toString(), null); Object match = properties.get(key); // TODO: Find a better way to solve minor type mismatches (Long!=Integer) than the string conversion below if (value == null || (match != null && !value.equals(match) && !value.toString().equals(match.toString()))) { return false; } } } return true; }
From source file:org.netbeans.modules.php.cake3.utils.JsonSimpleSupport.java
private static <T> T fromJson(Object o, Class<T> type) { if (type == String.class || type == Integer.class || type == Map.class || type == Long.class || type == List.class) { return type.cast(o); }/*from w w w . ja va 2 s. co m*/ JSONObject jsonObject = (JSONObject) o; T instance = null; try { instance = type.newInstance(); for (Object key : jsonObject.keySet()) { try { Field field = type.getDeclaredField((String) key); Object value = fromJson(jsonObject.get(key), field.getType()); field.setAccessible(true); field.set(instance, value); } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) { LOGGER.log(Level.WARNING, ex.getMessage()); } } } catch (InstantiationException | IllegalAccessException ex) { LOGGER.log(Level.WARNING, ex.getMessage()); } return instance; }
From source file:org.openstack.storlet.sbus.ServerSBusInDatagram.java
private void populateMetadata(HashMap<String, String> dest, JSONObject source) throws ParseException { for (Object key : source.keySet()) { String strKey = (String) key; String strVal = (String) source.get(key); dest.put(strKey, strVal);//from w w w. ja v a2 s . c o m } }
From source file:org.openstack.storlet.sbus.ServerSBusInDatagram.java
/** * Parses a raw message coming from the wire. * The incoming message is constructed by the ClientSBusOutDatagram. * The message is structured as follows: * Array of file descriptors, already parsed in SBusRawMessage * A command related json string of the following structure: * {// w ww . j a va 2 s . c o m * "command": "command encoded as string", * "params": { // This element is optional * "key1": "value1", * ... * }, * "task_id": "task id encoded as string" // This element is optional * } * File descriptors metadata, encoded as a JSON array with one * element per file descriptor. The i'th element in the array * consists of the metadata of the i'th element in the file * descriptors array: * [ * { * "storlets": { * "type": "the fd type encoded as string", // Mandatory * ... // Additional optional storlets metadata * }, * "storage": { * "metadata key1": "metadata value 1", * ... * } * }, * ... * ] * All the values in the above JSON elemens are strings. * Once constructed the class provides all necessary accessors to the parsed * fields. * @param msg the raw mwssage consisting of the string encoded json formats * @see SBusPythonFacade.ClientSBusOutDatagram the python code that serilializes the datagram * @see SBusPythonFacade.ServerSBusInDatagram the equivalent python code */ public ServerSBusInDatagram(final SBusRawMessage msg) throws ParseException { this.fds = msg.getFiles(); numFDs = this.fds == null ? 0 : this.fds.length; JSONObject jsonCmdParams = (JSONObject) (new JSONParser().parse(msg.getParams())); this.command = (String) jsonCmdParams.get("command"); this.params = new HashMap<String, String>(); if (jsonCmdParams.containsKey("params")) { JSONObject jsonParams = (JSONObject) jsonCmdParams.get("params"); for (Object key : jsonParams.keySet()) { this.params.put((String) key, (String) jsonParams.get(key)); } } if (jsonCmdParams.containsKey("task_id")) { this.taskID = (String) jsonCmdParams.get("task_id"); } String strMD = msg.getMetadata(); this.metadata = (HashMap<String, HashMap<String, String>>[]) new HashMap[getNFiles()]; JSONArray jsonarray = (JSONArray) (new JSONParser().parse(strMD)); Iterator it = jsonarray.iterator(); int i = 0; while (it.hasNext()) { this.metadata[i] = new HashMap<String, HashMap<String, String>>(); HashMap<String, String> storletsMetadata = new HashMap<String, String>(); HashMap<String, String> storageMetadata = new HashMap<String, String>(); JSONObject jsonobject = (JSONObject) it.next(); if (jsonobject.containsKey("storage")) { populateMetadata(storageMetadata, (JSONObject) jsonobject.get("storage")); } if (!jsonobject.containsKey("storlets")) { } else { populateMetadata(storletsMetadata, (JSONObject) jsonobject.get("storlets")); } this.metadata[i].put("storage", storageMetadata); this.metadata[i].put("storlets", storletsMetadata); i++; } }
From source file:org.owasp.dependencytrack.controller.ApplicationController.java
public void PLUGIN_MAIN() { try {/*w w w . ja v a2 s . c o m*/ /* Opening the JSON file and getting a JSONObject. */ // The "program_info.json" file has to be outside of the war file. JSONObject obj = _fileToJSONObject("/var/opt/dependency-track-pluggin/program_info.json"); /* Extracting the information from the JSONObject. */ @SuppressWarnings("unchecked") Set<String> programs = (Set<String>) obj.keySet(); for (String program : programs) { JSONArray array = (JSONArray) obj.get(program); JSONArray componentsProgram = (JSONArray) array.get(0); String versionProgram = (String) array.get(1); // We have now : program, components, version of a program /* Saving the applications in the database */ String idApplicationVersion = _addApplication(program, versionProgram); int len = componentsProgram.size(); for (int i = 0; i < len; i = i + 1) { @SuppressWarnings("unchecked") ArrayList<String> component = (ArrayList<String>) componentsProgram.get(i); String vendorComponent = component.get(0); String productComponent = component.get(1); String versionComponent = component.get(2); String languageComponent = component.get(3); String licenseComponent = component.get(4); // We have now : vendor, product, version, language, license // of a component /* Saving the library in the database. */ String idLibraryVersion = _addLibrary(productComponent, versionComponent, vendorComponent, licenseComponent, languageComponent); /* Adding the dependencies. */ _addDependencies(idApplicationVersion, idLibraryVersion); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.pentaho.js.require.RebuildCacheCallableTest.java
private static void testEquals(JSONObject object1, JSONObject object2) { assertEquals(object1.keySet(), object2.keySet()); for (Object key : object1.keySet()) { testEquals(object1.get(key), object2.get(key)); }//from ww w .j a v a 2 s . c om }