List of usage examples for org.json.simple.parser JSONParser parse
public Object parse(Reader in) throws IOException, ParseException
From source file:iracing.webapi.LicenseParser.java
public static List<License> parse(String json) { JSONParser parser = new JSONParser(); List<License> output = null; try {/*from w w w.ja va 2 s . c o m*/ JSONArray root = (JSONArray) parser.parse(json); output = new ArrayList<License>(); for (int i = 0; i < root.size(); i++) { JSONObject o = (JSONObject) root.get(i); License license = new License(); license.setId(getInt(o, "id")); license.setShortName(getString(o, "shortname")); license.setFullName(getString(o, "name", true)); output.add(license); } } catch (ParseException ex) { Logger.getLogger(LicenseParser.class.getName()).log(Level.SEVERE, null, ex); } return output; }
From source file:component.Configuration.java
public static boolean loadConfigFile() { Config loadConfig;//w w w .ja v a2s.co m try { File file = new File("config.json"); if (!file.exists()) { return false; } JSONParser parser = new JSONParser(); JSONObject object; object = (JSONObject) parser.parse(new FileReader(file)); loadConfig = new Config(); loadConfig.load(object); if (loadConfig.isConfigFill()) { Configuration.config = loadConfig; return true; } return false; } catch (IOException | ParseException ex) { return false; } }
From source file:com.serena.rlc.provider.jira.domain.Project.java
public static List<Project> parse(String options) { List<Project> list = new ArrayList<>(); JSONParser parser = new JSONParser(); try {/*from w ww .j av a 2 s . co m*/ Object parsedObject = parser.parse(options); JSONArray array = (JSONArray) parsedObject; for (Object object : array) { Project obj = new Project(); JSONObject jsonObject = (JSONObject) object; obj.setId((String) jsonObject.get("id")); obj.setName((String) jsonObject.get("name")); obj.setKey((String) jsonObject.get("key")); list.add(obj); } } catch (ParseException e) { logger.error("Error while parsing input JSON - " + options, e); } return list; }
From source file:mysynopsis.JSONReader.java
public static void readData() throws FileNotFoundException, IOException, ParseException { try {//from ww w. j a v a2 s . c om JSONParser parser = new JSONParser(); Object obj = parser.parse(new FileReader("data.json")); JSONObject read; read = (JSONObject) obj; name = (String) read.get("Name"); initial = (String) read.get("Initial"); biog = (String) read.get("Bio"); designation = (String) read.get("Designation"); dept = (String) read.get("Department"); university = (String) read.get("University"); universityAddress = (String) read.get("University_Address"); office = (String) read.get("Office"); officehours = (String) read.get("Ohours"); phone = (String) read.get("Phone"); email = (String) read.get("Email"); resumelink = (String) read.get("Resume_Link"); education = (String) read.get("Educational"); professional = (String) read.get("Professional"); awards = (String) read.get("Awards"); imgExtension = (String) read.get("Image_Ext"); imgString = (String) read.get("Image_String"); /*JSONArray education = (JSONArray) read.get("Education"); for(int i=0;i<8;i++) { educ[i] = (String) education.get(i); }*/ JSONArray ftpinfo = (JSONArray) read.get("Server_Information"); server = (String) ftpinfo.get(0); user = (String) ftpinfo.get(1); dir = (String) ftpinfo.get(2); } catch (IOException | ParseException e) { JOptionPane.showMessageDialog(null, "Something went wrong. Please re-run the software."); } }
From source file:autoancillarieslimited.parser.ParserUtil.java
public static WareHouses parserWarehouses(String dataJson) { try {/*w w w . j av a 2 s . c om*/ WareHouses i = new WareHouses(); JSONParser parser = new JSONParser(); Object obj = parser.parse(dataJson); JSONObject jsonObject = (JSONObject) obj; int id = Integer.parseInt((String) jsonObject.get("P0")); String name = (String) jsonObject.get("P1"); String address = (String) jsonObject.get("P2"); String phone = (String) jsonObject.get("P3"); String email = (String) jsonObject.get("P4"); int region_ID = Integer.parseInt((String) jsonObject.get("P5")); i.setId(id); i.setName(name); i.setAddress(address); i.setPhone(phone); i.setEmail(email); i.setRegion_ID(region_ID); return i; } catch (Exception ex) { return null; } }
From source file:h.scratchpads.list.json.JSONReader.java
private static JSONArray readJSON(String jsonFileUrl, LogFile logFile) { String info;/*www. j a v a 2 s . c o m*/ String jsonStr = URLReader.readFromUrl(jsonFileUrl, logFile); JSONArray arrayJSON = null; if (!HkStrings.isNullOrEmptyString(jsonStr)) { JSONParser parser = new JSONParser(); Object obj = null; try { obj = parser.parse(jsonStr); arrayJSON = (JSONArray) obj; } catch (ParseException ex) { info = "Unable to parse JSON file at the URL: \n" + jsonFileUrl + "\n"; info = info + "Exception: " + ex.getMessage(); logFile.write("\n!!!\n" + info + "\n!!!\n"); System.out.println(info); } } else { info = "No data from JSON file at URL: \n" + jsonFileUrl; logFile.write("\n!!!\n" + info + "\n!!!\n"); System.out.println(info); } return arrayJSON; }
From source file:com.serena.rlc.provider.artifactory.domain.Repository.java
public static Repository parseSingle(String options) { JSONParser parser = new JSONParser(); try {/* w w w.ja v a 2 s. co m*/ Object parsedObject = parser.parse(options); Repository repository = parseSingle((JSONObject) parsedObject); return repository; } catch (ParseException e) { logger.error("Error while parsing input JSON - " + options, e); } return null; }
From source file:iracing.webapi.SeasonQualifyingResultParser.java
public static long parse(String json, ItemHandler handler) { JSONParser parser = new JSONParser(); long output = 0; try {/*from w ww . j av a2 s . c om*/ JSONObject root = (JSONObject) parser.parse(json); //{"m":{"1":"bestqualtime","2":"sublevel","3":"custrow","4":"maxlicenselevel","5":"rank","6":"helmcolor1","7":"displayname","8":"helmcolor2","9":"division","10":"custid","11":"helmcolor3","12":"clubid","13":"helmpattern","14":"pos","15":"rowcount","16":"bestqualtimeformatted","17":"rn"},"d":{"3":"-1","15":6,"r":[{"1":1465493,"2":"+2.36","4":18,"5":1,"6":255,"7":"Mitchell+Abrahall","8":118,"9":1,"10":25765,"11":108,"12":34,"13":62,"14":1,"16":"2%3A26.549","17":1},{"1":1490441,"2":"+3.43","4":15,"5":2,"6":255,"7":"John+Briggs","8":255,"9":5,"10":73770,"11":255,"12":34,"13":12,"14":2,"16":"2%3A29.044","17":2},{"1":1496234,"2":"+4.51","4":16,"5":3,"6":255,"7":"Stephen+Jenkins","8":96,"9":3,"10":68792,"11":112,"12":34,"13":22,"14":3,"16":"2%3A29.623","17":3},{"1":1502289,"2":"+3.45","4":14,"5":4,"6":240,"7":"Dirk+Benecke","8":130,"9":1,"10":84055,"11":255,"12":42,"13":63,"14":4,"16":"2%3A30.228","17":4},{"1":1513869,"2":"+2.73","4":10,"5":5,"6":44,"7":"Wayne+Stroh","8":240,"9":3,"10":88615,"11":185,"12":34,"13":56,"14":5,"16":"2%3A31.386","17":5},{"1":1548511,"2":"+2.61","4":17,"5":6,"6":80,"7":"Kyle+Young","8":249,"9":2,"10":72798,"11":240,"12":14,"13":21,"14":6,"16":"2%3A34.851","17":6}]}} Object o = root.get("d"); if (o instanceof JSONObject) { JSONObject d = (JSONObject) o; output = getLong(d, "15"); JSONArray arrayRoot = (JSONArray) d.get("r"); for (int i = 0; i < arrayRoot.size(); i++) { JSONObject r = (JSONObject) arrayRoot.get(i); SeasonQualifyingResult result = new SeasonQualifyingResult(); result.setBestQualifyingTime(getLong(r, "1")); result.setLicenseSubLevel(getString(r, "2")); result.setMaxLicenseLevel(getInt(r, "4")); result.setRank(getInt(r, "5")); result.setDriverName(getString(r, "7", true)); result.setDivision(getInt(r, "9")); result.setDriverCustomerId(getLong(r, "10")); result.setClubId(getInt(r, "12")); result.setPosition(getLong(r, "14")); result.setBestQualifyingTimeFormatted(getString(r, "16", true)); handler.onSeasonQualifyingResultParsed(result); } } } catch (ParseException ex) { Logger.getLogger(SeasonQualifyingResultParser.class.getName()).log(Level.SEVERE, null, ex); } return output; }
From source file:me.cybermaxke.merchants.v16r3.SUtil.java
public static String fromJson(String json) throws ParseException { JSONParser parser = new JSONParser(); Object object = parser.parse(json); StringBuilder builder = new StringBuilder(); Data data = new Data(); data.builder = builder;//from w ww . j a v a2s .c om data.lastColor = ChatColor.WHITE; data.lastStyles = Sets.newHashSet(); apply(object, data); return builder.toString(); }
From source file:autoancillarieslimited.parser.ParserUtil.java
public static Employee parserEmployeeFromJSON(String dataJson) { try {// w w w. j a va 2 s. c om Employee i = new Employee(); JSONParser parser = new JSONParser(); Object obj = parser.parse(dataJson); JSONObject jsonObject = (JSONObject) obj; int id = Integer.parseInt((String) jsonObject.get("P0")); int warehouse_id = Integer.parseInt((String) jsonObject.get("P1")); String email = (String) jsonObject.get("P2"); String password = (String) jsonObject.get("P3"); String name = (String) jsonObject.get("P4"); String address = (String) jsonObject.get("P5"); String phone = (String) jsonObject.get("P6"); i.setId(id); i.setEmail(email); i.setPassword(password); i.setName(name); i.setAddress(address); i.setPhone(phone); WareHouses houses = WareHousesDAO.getInstance().getByID(warehouse_id, WareHouses.class); i.setWareHouses(houses); return i; } catch (Exception ex) { return null; } }