List of usage examples for org.json.simple JSONObject size
int size();
From source file:MyTest.ParseJson.java
public static void main(String args[]) { try {// www . j a v a2s. com FileReader reader = new FileReader( new File("data/NGS___RNA-seq_differential_expression_analysis-v1.ga")); System.out.println(reader); JSONParser parser = new JSONParser(); JSONObject jo = (JSONObject) parser.parse(reader); JSONObject jsteps = (JSONObject) jo.get("steps"); System.out.println(jsteps.size()); System.out.println("---------------------------------------------------"); for (int i = 0; i < jsteps.size(); i++) { JSONObject jstep_detail = (JSONObject) jsteps.get(String.valueOf(i)); getDetailInfo(jstep_detail); } } catch (FileNotFoundException ex) { Logger.getLogger(ParseJson.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ParseJson.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(ParseJson.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ch.newscron.encryption.Encryption.java
/** * Given a JSONObject, it is checked if it is a good JSONObject depending what data we need. * @param obj is the JSONObject to check * @return true if the JSONObject is a good one, false otherwise *//* w ww . j a v a2s. c o m*/ public static boolean checkDataValidity(JSONObject obj) { return obj != null && obj.size() == 4 && obj.get("custID") != null && !((String) obj.get("custID")).isEmpty() && obj.get("rew1") != null && !((String) obj.get("rew1")).isEmpty() && obj.get("rew2") != null && !((String) obj.get("rew2")).isEmpty() && obj.get("val") != null && !((String) obj.get("val")).isEmpty(); }
From source file:it.polimi.geinterface.filter.PropertiesFilter.java
protected static Filter buildJSONPathFilter(JSONObject json) { if (json == null) return null; if (json.size() != 3) { System.err.println("No 3 keys for object " + json); return null; }//from w w w .j a va 2s . c o m String operand = (String) json.get(ReservedKeys.$op.name()); FilterType op_type = FilterType.valueOf(operand); if (op_type.ordinal() <= FilterType.OR.ordinal()) { if (op_type.equals(FilterType.AND)) return buildJSONPathFilter((JSONObject) json.get(ReservedKeys.$filter_1.name())) .and(buildJSONPathFilter((JSONObject) json.get(ReservedKeys.$filter_2.name()))); return buildJSONPathFilter((JSONObject) json.get(ReservedKeys.$filter_1.name())) .or(buildJSONPathFilter((JSONObject) json.get(ReservedKeys.$filter_2.name()))); } else { String key = (String) json.get(ReservedKeys.$key.name()); String val = "" + json.get(ReservedKeys.$val.name()); if (op_type.equals(FilterType.CONTAINS)) return Filter.filter(Criteria.where((String) json.get(ReservedKeys.$key.name())) .contains(json.get(ReservedKeys.$val.name()))); if (op_type.equals(FilterType.EQUALS)) return Filter.filter(Criteria.where((String) json.get(ReservedKeys.$key.name())) .eq(json.get(ReservedKeys.$val.name()))); if (op_type.equals(FilterType.GT)) return Filter.filter(Criteria.where((String) json.get(ReservedKeys.$key.name())) .gt(json.get(ReservedKeys.$val.name()))); if (op_type.equals(FilterType.LT)) return Filter.filter(Criteria.where((String) json.get(ReservedKeys.$key.name())) .lt(json.get(ReservedKeys.$val.name()))); if (op_type.equals(FilterType.EXISTS)) return Filter.filter(Criteria.where((String) json.get(ReservedKeys.$key.name())) .exists((boolean) json.get(ReservedKeys.$val.name()))); if (op_type.equals(FilterType.NOT_EXISTS)) return Filter.filter(Criteria.where((String) json.get(ReservedKeys.$key.name())) .exists((boolean) json.get(ReservedKeys.$val.name()))); } return null; }
From source file:com.bigdata.dastor.tools.SSTableImport.java
/** * Convert a JSON formatted file to an SSTable. * /*from w w w. j a v a 2s .co m*/ * @param jsonFile the file containing JSON formatted data * @param keyspace keyspace the data belongs to * @param cf column family the data belongs to * @param ssTablePath file to write the SSTable to * @throws IOException for errors reading/writing input/output * @throws ParseException for errors encountered parsing JSON input */ public static void importJson(String jsonFile, String keyspace, String cf, String ssTablePath) throws IOException, ParseException { ColumnFamily cfamily = ColumnFamily.create(keyspace, cf); String cfType = cfamily.type(); // Super or Standard IPartitioner<?> partitioner = DatabaseDescriptor.getPartitioner(); DataOutputBuffer headerBuffer = new DataOutputBuffer(); // BIGDATA DataOutputBuffer dob = new DataOutputBuffer(); try { JSONObject json = (JSONObject) JSONValue.parseWithException(new FileReader(jsonFile)); SSTableWriter writer = new SSTableWriter(ssTablePath, json.size(), partitioner); List<DecoratedKey<?>> decoratedKeys = new ArrayList<DecoratedKey<?>>(); for (String key : (Set<String>) json.keySet()) decoratedKeys.add(partitioner.decorateKey(key)); Collections.sort(decoratedKeys); for (DecoratedKey<?> rowKey : decoratedKeys) { if (cfType.equals("Super")) addToSuperCF((JSONObject) json.get(rowKey.key), cfamily); else addToStandardCF((JSONArray) json.get(rowKey.key), cfamily); ColumnFamily.serializer().serializeWithIndexes(cfamily, headerBuffer, dob, DatabaseDescriptor.getCompressAlgo(keyspace, cf)); // BIGDATA writer.append(rowKey, headerBuffer, dob); headerBuffer.reset(); // BIGDATA dob.reset(); cfamily.clear(); } writer.closeAndOpenReader(); } catch (ClassCastException cce) { throw new RuntimeException("Invalid JSON input, or incorrect column family.", cce); } }
From source file:eu.wordnice.wnconsole.WNCUtils.java
public static Map<String, Object> sortObject(JSONObject jo) { Object[] names = new Object[jo.size()]; Object[] values = new Object[jo.size()]; boolean[] used = new boolean[jo.size()]; boolean curHas = false; Object[] in = jo.keySet().toArray(); int i = 0;//from w ww.jav a 2 s.com int i2 = 0; for (; i < jo.size(); i++) { curHas = false; for (i2 = 0; i2 < jo.size(); i2++) { String cname = (String) in[i2]; if (!used[i2] && cname.startsWith("get")) { names[i] = ("" + cname); values[i] = jo.get(cname); used[i2] = true; curHas = true; break; } } if (!curHas) { break; } } i2 = 0; for (/* continue */; i < jo.size(); i++) { for (/* continue */; i2 < jo.size(); i2++) { String cname = (String) in[i2]; if (!used[i2]) { names[i] = cname; values[i] = jo.get(cname); used[i2] = true; curHas = true; break; } } } Map<String, Object> map = new Map<String, Object>(); map.names = names; map.values = values; map.size = names.length; return map; }
From source file:com.worldline.easycukes.commons.helpers.JSONHelper.java
/** * Returns <b>true</b> if JSON object o1 is equals to JSON object o2. * * @param o1 a {@link JSONObject} containing some JSON data * @param o2 another {@link JSONObject} containing some JSON data * @return true if the json objects are equals *///from www . j a v a2 s. co m public static boolean equals(@NonNull JSONObject o1, @NonNull JSONObject o2) { if (o1 == o2) return true; if (o1.size() != o2.size()) return false; try { final Iterator<Entry<String, Object>> i = o1.entrySet().iterator(); while (i.hasNext()) { final Entry<String, Object> e = i.next(); final String key = e.getKey(); final Object value1 = e.getValue(); final Object value2 = o2.get(key); if (value1 == null) { if (!(o2.get(key) == null && o2.containsKey(key))) return false; } else if (value1 instanceof JSONObject) { if (!(value2 instanceof JSONObject)) return false; if (!equals((JSONObject) value1, (JSONObject) value2)) return false; } else if (value1 instanceof JSONArray) { if (!(value2 instanceof JSONArray)) return false; if (!equals((JSONArray) value1, (JSONArray) value2)) return false; } else if (!value1.equals(value2)) return false; } } catch (final Exception unused) { unused.printStackTrace(); return false; } return true; }
From source file:com.intel.genomicsdb.GenomicsDBImporter.java
/** * Utility function that returns a list of ChromosomeInterval objects for * the column partition specified by the loader JSON file and rank/partition index * @param loaderJSONFile path to loader JSON file * @param partitionIdx rank/partition index * @return list of ChromosomeInterval objects for the specified partition * @throws ParseException when there is a bug in the JNI interface and a faulty JSON is returned *///from ww w . j a v a2s . c om public static ArrayList<ChromosomeInterval> getChromosomeIntervalsForColumnPartition( final String loaderJSONFile, final int partitionIdx) throws ParseException { final String chromosomeIntervalsJSONString = jniGetChromosomeIntervalsForColumnPartition(loaderJSONFile, partitionIdx); /* JSON format { "contigs": [ { "chr1": [ 100, 200] }, { "chr2": [ 500, 600] } ] } */ ArrayList<ChromosomeInterval> chromosomeIntervals = new ArrayList<ChromosomeInterval>(); JSONParser parser = new JSONParser(); JSONObject topObj = (JSONObject) (parser.parse(chromosomeIntervalsJSONString)); assert topObj.containsKey("contigs"); JSONArray listOfDictionaries = (JSONArray) (topObj.get("contigs")); for (Object currDictObj : listOfDictionaries) { JSONObject currDict = (JSONObject) currDictObj; assert currDict.size() == 1; //1 entry for (Object currEntryObj : currDict.entrySet()) { Map.Entry<String, JSONArray> currEntry = (Map.Entry<String, JSONArray>) currEntryObj; JSONArray currValue = currEntry.getValue(); assert currValue.size() == 2; chromosomeIntervals.add(new ChromosomeInterval(currEntry.getKey(), (Long) (currValue.get(0)), (Long) (currValue.get(1)))); } } return chromosomeIntervals; }
From source file:com.netflix.priam.cassandra.extensions.PriamStartupAgent.java
private void setExtraEnvParams(String extraEnvParams) { try {/*from w ww . j av a 2s . c om*/ if (null != extraEnvParams && extraEnvParams.length() > 0) { JSONParser parser = new JSONParser(); Object obj = parser.parse(extraEnvParams); JSONObject jsonObj = (JSONObject) obj; if (jsonObj.size() > 0) { for (Iterator iterator = jsonObj.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); String val = (String) jsonObj.get(key); if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(val)) { System.setProperty(key.trim(), val.trim()); } } } } } catch (Exception e) { System.out.println( "Failed to parse extra env params: " + extraEnvParams + ". However, ignoring the exception."); e.printStackTrace(); } }
From source file:lockers.FrameCobro.java
private void getRates() { JSONArray array = Utils.getJSONArrayFromURL("http://127.0.0.1:8000/Rates/?format=json"); if (array.size() == 0) { this.jLblAvailableLockers.setText("No hay disponibilidad"); } else {/* www . j a v a 2 s . com*/ for (Object array1 : array) { JButton nuevo = new JButton(); JSONObject obj2 = (JSONObject) array1; System.out.println(obj2.size()); nuevo.setText(obj2.get("rate_name") + ": " + obj2.get("rate_rate")); nuevo.setVisible(true); nuevo.setSize(200, 50); nuevo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source instanceof JButton) { JButton btn = (JButton) source; System.out.println("You clicked the button " + btn.getText()); } } }); this.jPanel1.add(nuevo); } } }
From source file:io.fabric8.jolokia.assertions.JSONObjectAssert.java
/** * Returns the value for the given key//from ww w. j a v a 2 s . c o m */ public Object value(String key) { JSONObject value = get(); assertThat(value.size()).isGreaterThan(0); return value.get(key); }