List of usage examples for org.json.simple.parser ParseException printStackTrace
public void printStackTrace()
From source file:it.avalz.opendaylight.controller.examples.JsonParser.java
public static void main(String[] args) { String s = "{\"ids\":[\"00:00:00:00:00:00:00:01\", \"00:00:00:00:00:00:00:02\"], \"width\":200, \"height\":100}"; JSONObject json = null;//w ww. j a va 2s . c o m try { json = (JSONObject) new JSONParser().parse(s); } catch (ParseException ex) { ex.printStackTrace(); } System.out.println(json.get("ids")); JSONArray array = (JSONArray) json.get("ids"); System.out.println(array.get(0)); System.out.println(json.get("width")); System.out.println(json.get("height")); List<String> l = new ArrayList<String>(); l.add("\"DROP\""); l.add("\"OUTPUT=2\""); System.out.println(l); }
From source file:jnilibxml2.java
public static void main(String[] args) { // Create Json parser JSONParser parser = new JSONParser(); // Create string that will hold the native call's return String[] LibReturnString = new String[args.length]; Integer i = 0;//from w ww. j a v a 2s . c om if (args.length < 0) { System.out.println("Please supply a file to parse in commandline"); } try { // allow the user to supply as many xml files as they wish for (i = 0; i < args.length; i++) { // run the native call on the file and get the string LibReturnString[i] = xmlparsefile(args[i]); Object obj = parser.parse(LibReturnString[i]); // JSON object is parsed and ready JSONObject jsonObject = (JSONObject) obj; // Dump it to output to confirm everything is functioning. System.out.println(jsonObject); } } catch (ParseException e) { e.printStackTrace(); } }
From source file:com.devdungeon.simplejson.DecodeJson.java
public static void main(String[] args) { try {/* www . ja v a 2s . co m*/ String jsonData = getJsonFromUrl("http://www.reddit.com/r/houston.json"); JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject) jsonParser.parse(jsonData); // The whole JSON value //System.out.println(jsonObject); JSONObject data = (JSONObject) jsonObject.get("data"); // The data object //System.out.println(data); JSONArray children = (JSONArray) data.get("children"); // All children // for each child in children // get child("data") for (int i = 0; i < children.size(); i++) { JSONObject child = (JSONObject) children.get(i); //System.out.println(child); // The whole post object JSONObject childData = (JSONObject) child.get("data"); System.out.print(childData.get("title") + ": "); System.out.println(childData.get("url")); } } catch (ParseException ex) { ex.printStackTrace(); } catch (NullPointerException ex) { ex.printStackTrace(); } }
From source file:com.aj.hangman.HangmanReq.java
public static void main(String[] args) { HangmanDict dictionary = new HangmanDict(); try {//from ww w. j ava 2s .c o m BufferedReader input = new BufferedReader(new InputStreamReader( new URL("http://gallows.hulu.com/play?code=gudehosa@usc.edu").openStream())); String info = input.readLine(); JSONParser parser = new JSONParser(); Object obj; try { obj = parser.parse(info); JSONObject retJson = (JSONObject) obj; TOKEN = (String) retJson.get("token"); STATUS = (String) retJson.get("status"); STATE = (String) retJson.get("state"); REM = (Long) retJson.get("remaining_guesses"); PREM = REM; System.out.println("State:: " + STATE); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } while ("ALIVE".equalsIgnoreCase(STATUS)) { // call make guess function, returns character guess = dictionary.makeGuess(STATE); System.out.println("Guessed:: " + guess); // call the url to update BufferedReader reInput = new BufferedReader( new InputStreamReader(new URL("http://gallows.hulu.com/play?code=gudehosa@usc.edu" + String.format("&token=%s&guess=%s", TOKEN, guess)).openStream())); // parse the url to get the updated value String reInfo = reInput.readLine(); JSONParser reParser = new JSONParser(); Object retObj = reParser.parse(reInfo); JSONObject retJson = (JSONObject) retObj; STATUS = (String) retJson.get("status"); STATE = (String) retJson.get("state"); REM = (Long) retJson.get("remaining_guesses"); System.out.println("State:: " + STATE); } if ("DEAD".equalsIgnoreCase(STATUS)) { // print lost System.out.println("You LOOSE: DEAD"); } else if ("FREE".equalsIgnoreCase(STATUS)) { // print free System.out.println("You WIN: FREE"); } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.opensoc.json.serialization.JSONKafkaSerializer.java
public static void main(String args[]) throws IOException { //String Input = "/home/kiran/git/opensoc-streaming/OpenSOC-Common/BroExampleOutput"; String Input = "/tmp/test"; BufferedReader reader = new BufferedReader(new FileReader(Input)); // String jsonString = // "{\"dns\":{\"ts\":[14.0,12,\"kiran\"],\"uid\":\"abullis@mail.csuchico.edu\",\"id.orig_h\":\"10.122.196.204\", \"endval\":null}}"; String jsonString = "";// reader.readLine(); JSONParser parser = new JSONParser(); JSONObject json = null;/*from w w w . j av a 2 s . c o m*/ int count = 1; if (args.length > 0) count = Integer.parseInt(args[0]); //while ((jsonString = reader.readLine()) != null) jsonString = reader.readLine(); { try { json = (JSONObject) parser.parse(jsonString); System.out.println(json); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } String jsonString2 = null; JSONKafkaSerializer ser = new JSONKafkaSerializer(); for (int i = 0; i < count; i++) { byte[] bytes = ser.toBytes(json); jsonString2 = ((JSONObject) ser.fromBytes(bytes)).toJSONString(); } System.out.println((jsonString2)); System.out.println(jsonString2.equalsIgnoreCase(json.toJSONString())); } }
From source file:UserHistoryGUI.java
public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html *//*from w w w. j a va 2 s . c o m*/ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(UserHistoryGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(UserHistoryGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(UserHistoryGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(UserHistoryGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { try { new UserHistoryGUI("JayJung").setVisible(true); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); }
From source file:com.textquo.dreamcode.server.JSONHelper.java
public static Map<String, Object> parseJson(String jsonText) { Map<String, Object> json = null; try {/*from w w w. j a va 2s .co m*/ org.json.simple.parser.JSONParser parser = new org.json.simple.parser.JSONParser(); ContainerFactory containerFactory = new ContainerFactory() { public List creatArrayContainer() { return new LinkedList(); } public Map createObjectContainer() { return new LinkedHashMap(); } }; json = (Map<String, Object>) parser.parse(jsonText, containerFactory); Iterator iter = json.entrySet().iterator(); LOG.info("==iterate result=="); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); LOG.info(entry.getKey() + "=>" + entry.getValue()); } LOG.info("==toJSONString()=="); LOG.info(org.json.simple.JSONValue.toJSONString(json)); } catch (ParseException e) { e.printStackTrace(); } return json; }
From source file:it.polimi.proximityapi.jsonLogic.POIJsonParser.java
public static ArrayList<POI> parsePOIFile(String jsonString) { ArrayList<POI> poiList = new ArrayList<>(); JSONParser parser = new JSONParser(); JSONArray poiArray;/*from ww w . ja v a 2 s .c om*/ try { poiArray = (JSONArray) parser.parse(jsonString); for (int i = 0; i < poiArray.size(); i++) { JSONObject jsonPOI = (JSONObject) poiArray.get(i); POI poi = new POI(); poi.setName((String) jsonPOI.get(JsonStrings.NAME)); poi.setLatitude(Double.parseDouble((String) jsonPOI.get(JsonStrings.LATITUDE))); poi.setLongitude(Double.parseDouble((String) jsonPOI.get(JsonStrings.LONGITUDE))); if (!jsonPOI.get(JsonStrings.RADIUS).equals("")) poi.setRadius(Float.parseFloat((String) jsonPOI.get(JsonStrings.RADIUS))); else { //Default radius set when it is not set in the corresponding JSON object poi.setRadius(TechnologyManager.BT_START_GEOFENCE_RADIUS); } poi.setBeaconUuid((String) jsonPOI.get(JsonStrings.BEACON_UUID)); poiList.add(poi); } } catch (ParseException e) { e.printStackTrace(); } return poiList; }
From source file:com.healthcit.analytics.utils.ExcelExportUtils.java
public static JSONObject getAsJsonObject(String jsonString) { JSONObject obj = null;/*from w ww . j av a2s .c o m*/ try { obj = (JSONObject) JSONValue.parseWithException(jsonString); } catch (ParseException e) { e.printStackTrace(); } return obj; }
From source file:com.healthcit.analytics.utils.ExcelExportUtils.java
public static JSONArray getAsJsonArray(String jsonString) { JSONArray arr = null;/*from w ww. j a va2 s . c om*/ try { arr = (JSONArray) JSONValue.parseWithException(jsonString); } catch (ParseException e) { e.printStackTrace(); } return arr; }