List of usage examples for org.json.simple.parser JSONParser parse
public Object parse(Reader in) throws IOException, ParseException
From source file:com.domsplace.DomsCommands.Objects.Chat.DomsChatObject.java
public static DomsChatObject createFromString(String msg) { try {//w w w . j a va 2 s. c o 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:com.ijuru.ijambo.Context.java
/** * Connects to the database//from w ww. j a v a 2s .c om * @return the Mongo DB * @throws ParseException * @throws UnknownHostException */ public static DB connectDatabase() throws ParseException, UnknownHostException { // Check for AppFog environment String appFogEnv = System.getenv("VCAP_SERVICES"); if (appFogEnv != null) { // Connect to MongoDB as AppFog service JSONParser parser = new JSONParser(); JSONObject svcs = (JSONObject) parser.parse(appFogEnv); JSONArray mongoSettings = (JSONArray) svcs.get("mongodb-1.8"); JSONObject mongoSettings0 = (JSONObject) mongoSettings.get(0); JSONObject mongoCreds0 = (JSONObject) mongoSettings0.get("credentials"); //String db = (String)mongoCreds0.get("db"); String connectionURL = (String) mongoCreds0.get("url"); log.info("Running as AppFog instance with connection URL: " + connectionURL); DB db = new MongoURI(connectionURL).connectDB(); // https://jira.mongodb.org/browse/JAVA-436 db.authenticate((String) mongoCreds0.get("username"), ((String) mongoCreds0.get("password")).toCharArray()); return db; } // Create default MongoDB instance m = new Mongo(); return m.getDB("ijambo"); }
From source file:com.serena.rlc.provider.artifactory.domain.Artifact.java
public static List<Artifact> parse(String options) { List<Artifact> list = new ArrayList<>(); JSONParser parser = new JSONParser(); try {/*from w w w.jav a 2 s .co m*/ Object parsedObject = parser.parse(options); JSONArray jsonArray = (JSONArray) getJSONValue((JSONObject) parsedObject, "results"); for (Object object : jsonArray) { Artifact aObj = parseSingle((JSONObject) object); list.add(aObj); } } catch (ParseException e) { logger.error("Error while parsing input JSON - " + options, e); } return list; }
From source file:io.github.casnix.spawnerdropper.Config.java
public static int GetCreeperChance() { try {//from w ww. ja v a2s . co m // Read entire ./SpawnerDropper/SpawnerDropperConfig.json into a string // System.out.println("[SD DEBUG] 7"); String configTable = new String( Files.readAllBytes(Paths.get("./plugins/SpawnerDropper/SpawnerDropperConfig.json"))); // get the value of JSON->{spawnerType} // System.out.println("[SD DEBUG] 8"); JSONParser parser = new JSONParser(); // System.out.println("[SD DEBUG] 9"); Object obj = parser.parse(configTable); //System.out.println("[SD DEBUG] 10"); JSONObject jsonObj = (JSONObject) obj; // System.out.println("[SD DEBUG] 11"); String chance = (String) jsonObj.get("creeperpercent"); // System.out.println("[SD DEBUG] 12"); return Integer.valueOf(chance); } catch (ParseException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in GetCreeperChance(void)"); e.printStackTrace(); return -1; } catch (FileNotFoundException e) { Bukkit.getLogger() .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerDropperConfig.json"); e.printStackTrace(); return -1; } catch (IOException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in GetCreeperChance(void)"); e.printStackTrace(); return -1; } catch (NumberFormatException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught NumberFormatException in GetCreeperChance(void)"); e.printStackTrace(); return -1; } }
From source file:manager.GameElement.java
public static void load() throws FileNotFoundException, IOException, ParseException, InstantiationException, IllegalAccessException {/* www . j av a 2s. c o m*/ BufferedReader br = new BufferedReader(new FileReader("scores.json")); JSONParser parser = new JSONParser(); String line = br.readLine(); if (line != null) fromJSON((JSONObject) parser.parse(line)); }
From source file:com.example.prathik1.drfarm.OCRRestAPI.java
private static void PrintOCRResponse(String jsonResponse) throws ParseException, IOException { // Parse JSON data JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(jsonResponse); // Get available pages System.out.println("Available pages: " + jsonObj.get("AvailablePages")); // get an array from the JSON object JSONArray text = (JSONArray) jsonObj.get("OCRText"); // For zonal OCR: OCRText[z][p] z - zone, p - pages for (int i = 0; i < text.size(); i++) { System.out.println(" " + text.get(i)); }//from w w w .ja v a2 s. co m // Output file URL String outputFileUrl = (String) jsonObj.get("OutputFileUrl"); // If output file URL is specified if (outputFileUrl != null && !outputFileUrl.equals("")) { // Download output file DownloadConvertedFile(outputFileUrl); } }
From source file:io.github.casnix.spawnerdropper.Config.java
public static int GetTNTChance() { try {/*from ww w . j av a 2s . c o m*/ // Read entire ./SpawnerDropper/SpawnerDropperConfig.json into a string // System.out.println("[SD DEBUG] 1"); String configTable = new String( Files.readAllBytes(Paths.get("./plugins/SpawnerDropper/SpawnerDropperConfig.json"))); // get the value of JSON->{spawnerType} // System.out.println("[SD DEBUG] 2"); JSONParser parser = new JSONParser(); // System.out.println("[SD DEBUG] 3"); Object obj = parser.parse(configTable); //System.out.println("[SD DEBUG] 4"); JSONObject jsonObj = (JSONObject) obj; // System.out.println("[SD DEBUG] 5"); String chance = (String) jsonObj.get("tntpercent"); // System.out.println("[SD DEBUG] 6"); // if(chance != null) // System.out.println("[SD DBG MSG] "+chance); // else // System.out.println("[SD DBG MSG] chance is null"); // System.out.println("[SD DEBUG] 7"); return Integer.valueOf(chance); //System.out.println("[SD DEBUG] 6"); //return chance; } catch (ParseException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in GetTNTChance(void)"); e.printStackTrace(); return -1; } catch (FileNotFoundException e) { Bukkit.getLogger() .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerDropperConfig.json"); e.printStackTrace(); return -1; } catch (IOException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in GetTNTChance(void)"); e.printStackTrace(); return -1; } }
From source file:io.github.casnix.spawnerdropper.SpawnerStack.java
public static boolean PutSpawnerIntoService(String spawnerType) { // Read ./SpawnerDropper.SpawnerStack.json into a string // get the value of JSON->{spawnerType} and add 1 to it. // Write file back to disk try {//from w ww.j a va 2 s . c om // Read entire ./SpawnerDropper.SpawnerStack.json into a string String spawnerStack = new String( Files.readAllBytes(Paths.get("./plugins/SpawnerDropper/SpawnerStack.json"))); // get the value of JSON->{spawnerType} JSONParser parser = new JSONParser(); Object obj = parser.parse(spawnerStack); JSONObject jsonObj = (JSONObject) obj; long numberInService = (Long) jsonObj.get(spawnerType); if (numberInService < 0) { numberInService = 0; } // System.out.println("[SD DBG MSG] PSIS numberInServer("+numberInService+")"); numberInService += 1; jsonObj.put(spawnerType, new Long(numberInService)); FileWriter file = new FileWriter("./plugins/SpawnerDropper/SpawnerStack.json"); file.write(jsonObj.toJSONString()); file.flush(); file.close(); return true; } catch (ParseException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in PutSpawnerIntoService(String)"); e.printStackTrace(); return false; } catch (FileNotFoundException e) { Bukkit.getLogger() .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerStack.json"); e.printStackTrace(); return false; } catch (IOException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in PutSpawnerIntoService(String)"); e.printStackTrace(); return false; } }
From source file:biomine.bmvis2.pipeline.GraphOperationSerializer.java
public static List<GraphOperation> loadList(String json) throws GraphOperationSerializationException { JSONParser par = new JSONParser(); JSONArray arr = null;// www .j a va 2s.c om try { System.out.println("obj = " + par.parse(json)); arr = (JSONArray) par.parse(json); } catch (ParseException e) { System.out.println(e); } return loadList(arr); }
From source file:io.github.casnix.spawnerdropper.SpawnerStack.java
public static boolean TakeSpawnerOutOfService(String spawnerType) { // Read ./SpawnerDropper.SpawnerStack.json into a string // get the value of JSON->{spawnerType} and subtract 1 to it unless it is 0. // If it's zero, return false // Write file back to disk try {// w w w. j av a 2 s .c om // Read entire ./SpawnerDropper.SpawnerStack.json into a string String spawnerStack = new String( Files.readAllBytes(Paths.get("./plugins/SpawnerDropper/SpawnerStack.json"))); // get the value of JSON->{spawnerType} JSONParser parser = new JSONParser(); Object obj = parser.parse(spawnerStack); JSONObject jsonObj = (JSONObject) obj; long numberInService = (Long) jsonObj.get(spawnerType); if (numberInService <= 0) { return false; } else { // System.out.println("[SD DBG MSG] TSOOS numberInServer("+numberInService+")"); numberInService -= 1; jsonObj.put(spawnerType, new Long(numberInService)); FileWriter file = new FileWriter("./plugins/SpawnerDropper/SpawnerStack.json"); file.write(jsonObj.toJSONString()); file.flush(); file.close(); return true; } } catch (ParseException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in TakeSpawnerOutOfService(String)"); e.printStackTrace(); return false; } catch (FileNotFoundException e) { Bukkit.getLogger() .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerStack.json"); e.printStackTrace(); return false; } catch (IOException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in TakeSpawnerOutOfService(String)"); e.printStackTrace(); return false; } }