List of usage examples for org.json.simple JSONObject keySet
Set<K> keySet();
From source file:com.storageroomapp.client.field.ImageVersion.java
static public List<ImageVersion> parseJSONListObject(JSONObject jsonObj) { @SuppressWarnings("unchecked") Set<String> identifiers = (Set<String>) jsonObj.keySet(); List<ImageVersion> versions = new ArrayList<ImageVersion>(); for (String identifier : identifiers) { JSONObject versionObject = (JSONObject) jsonObj.get(identifier); String url = (String) versionObject.get("@url"); if (url != null) { ImageVersion newVersion = new ImageVersion(identifier, url); versions.add(newVersion);/*www. j av a2 s .co m*/ } } return versions; }
From source file:com.facebook.tsdb.tsdash.server.model.MetricQuery.java
public static HashMap<String, String> decodeTags(JSONObject tagsObj) { HashMap<String, String> tags = new HashMap<String, String>(); for (Object tagKeyObj : tagsObj.keySet()) { tags.put((String) tagKeyObj, (String) tagsObj.get(tagKeyObj)); }/* w ww . j av a 2 s.co m*/ return tags; }
From source file:me.fromgate.messagecommander.PLListener.java
private static String jsonToString(JSONObject source) { String result = ""; for (Object key : source.keySet()) { Object value = source.get(key); if (value instanceof String) { if ((key instanceof String) && (!((String) key).equalsIgnoreCase("text"))) continue; result = result + (String) value; } else if (value instanceof JSONObject) { result = result + jsonToString((JSONObject) value); } else if (value instanceof JSONArray) { result = result + jsonToString((JSONArray) value); }/* w w w .j a va2s.c o m*/ } return result; }
From source file:me.fromgate.reactions.externals.RAProtocolLib.java
private static String jsonToString(JSONObject source) { String result = ""; for (Object key : source.keySet()) { Object value = source.get(key); if (value instanceof String) { if ((key instanceof String) && (!((String) key).equalsIgnoreCase("text"))) continue; result = result + value;//from w ww . j a v a 2 s .co m } else if (value instanceof JSONObject) { result = result + jsonToString((JSONObject) value); } else if (value instanceof JSONArray) { result = result + jsonToString((JSONArray) value); } } return result; }
From source file:MyTest.ParseJson.java
private static void getDetailInfo(JSONObject jstep_detail) { // System.out.println(jstep_detail); long id = (long) jstep_detail.get("id"); System.out.println("id:" + id); String name = (String) jstep_detail.get("name"); System.out.println("name:" + name); JSONArray inputs = (JSONArray) jstep_detail.get("inputs"); if (inputs.isEmpty()) { System.out.println("inputs:null"); } else {/*from w ww . j av a2 s . c o m*/ System.out.println("inputs:"); for (int i = 0; i < inputs.size(); i++) { System.out.println(inputs.get(i) + "\n"); } } JSONArray outpus = (JSONArray) jstep_detail.get("outputs"); if (outpus.isEmpty()) { System.out.println("outpus:null"); } else { System.out.println("outpus:"); for (int i = 0; i < outpus.size(); i++) { System.out.print(outpus.get(i) + "\n"); } } JSONObject links = (JSONObject) jstep_detail.get("input_connections"); if (links.isEmpty()) { System.out.println("input_connections:null"); } else { Iterator it = links.keySet().iterator(); System.out.println("input_connections: "); while (it.hasNext()) { Object input_link = it.next(); System.out.println(links.get(input_link)); } } System.out.println("-------------------------------------------------------"); }
From source file:com.justgiving.raven.kissmetrics.utils.KissmetricsLocalSchemaExtractor.java
/**** * This function counts the total occurrences of keys, in the json records files * /*w w w. j a va2s . c om*/ * @param input_filename path to a json file * @return a HashMap with the keys / total counts pairs */ private static KeyValueCounter countKeysInJsonRecordsFile(String input_filename) { InputStream fis; BufferedReader bufferedReader; String line; JSONParser jsonParser = new JSONParser(); KeyValueCounter keyValueCounter = new KeyValueCounter(); String jsonValue = ""; try { fis = new FileInputStream(input_filename); bufferedReader = new BufferedReader(new InputStreamReader(fis, Charset.forName("UTF-8"))); while ((line = bufferedReader.readLine()) != null) { JSONObject jsonObject = (JSONObject) jsonParser.parse(line); Set<String> keyset = jsonObject.keySet(); for (String jsonkey : keyset) { if (jsonObject.get(jsonkey) != null) { jsonValue = (String) jsonObject.get(jsonkey).toString(); if (jsonValue == null || jsonValue == "") { jsonValue = ""; } int lenValue = jsonValue.length(); keyValueCounter.incrementKeyCounter(jsonkey); keyValueCounter.putValueLength(jsonkey, lenValue); } else { if (jsonkey.compareTo("user_agent") != 0) { logger.error("Errot typing to get jsonkey " + jsonkey); } } } } bufferedReader.close(); } catch (ParseException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } //System.out.println(keyCounter.toString()); //System.out.println(sortHashByKey(keyCounter)); return keyValueCounter; }
From source file:com.p000ison.dev.copybooks.util.Helper.java
public static ArrayList<String> fromJSONStringtoList(String key, String string) { if (string != null && !string.isEmpty()) { ArrayList<String> out = new ArrayList<String>(); JSONObject flags = (JSONObject) JSONValue.parse(string); if (flags != null) { for (Object keys : flags.keySet()) { try { if (keys.equals(key)) { JSONArray list = (JSONArray) flags.get(keys); if (list != null) { for (Object k : list) { out.add(k.toString()); }/*from w ww . j a va 2 s . c o m*/ } } } catch (Exception ex) { CopyBooks.debug(String.format("Failed reading flag: %s", keys)); CopyBooks.debug(String.format("Value: %s", flags.get(key))); CopyBooks.debug(null, ex); } } } return out; } return null; }
From source file:com.walmartlabs.mupd8.application.Config.java
@SuppressWarnings("unchecked") private static void apply(JSONObject destination, JSONObject source) { for (Object k : source.keySet()) { String key = (String) k; if (destination.containsKey(key) && (destination.get(key) != null) && (destination.get(key) instanceof JSONObject) && (source.get(key) instanceof JSONObject)) { try { JSONObject subDestination = (JSONObject) destination.get(key); JSONObject subSource = (JSONObject) source.get(key); apply(subDestination, subSource); } catch (ClassCastException e) { throw new ClassCastException("Config: cannot override key " + key + " with new value because it is not a JSON object"); }// w ww . j a v a 2 s. co m } else { destination.put(key, source.get(key)); } } }
From source file:com.domsplace.DomsCommands.Objects.Chat.DomsChatObject.java
public static DomsChatObject createFromString(String msg) { try {/* w w w. ja v a 2 s .co m*/ JSONParser parser = new JSONParser(); JSONObject object = (JSONObject) parser.parse(msg); DomsChatObject obj = new DomsChatObject(); for (Object item : object.keySet()) { Object value = object.get(item); String key = item.toString(); } return obj; } catch (Exception e) { return null; } }
From source file:it.polimi.geinterface.filter.PropertiesFilter.java
/** * Method that parse a JSON {@link String} representing a filter into the corresponding {@link PropertiesFilter} * @param jsonPropFilter - the JSON {@link String} representing the filter * @return the corresponding {@link PropertiesFilter} *//* w w w. ja va 2 s. c o m*/ public static PropertiesFilter parseFromString(String jsonPropFilter) throws Exception { JSONParser p = new JSONParser(); try { JSONObject obj = (JSONObject) p.parse(jsonPropFilter); PropertiesFilter ret = new PropertiesFilter(); for (Object key : obj.keySet()) ret.put(key, obj.get(key)); return ret; } catch (ParseException e) { e.printStackTrace(); throw new Exception("Error parsing filter " + jsonPropFilter); } }