List of usage examples for org.json.simple.parser JSONParser JSONParser
JSONParser
From source file:com.serena.rlc.provider.jira.domain.Project.java
public static Project parseSingle(String options) { JSONParser parser = new JSONParser(); try {/*from w ww .ja v a2s .c o m*/ Object parsedObject = parser.parse(options); JSONObject jsonObject = (JSONObject) parsedObject; Project project = parseSingle(jsonObject); return project; } catch (ParseException e) { logger.error("Error while parsing input JSON - " + options, e); } return null; }
From source file:naftoreiclag.villagefive.SaveLoad.java
public static World load(Node rootNode, AssetManager assetManager) throws IOException, ParseException { World world = new World(rootNode, assetManager); JSONParser parser = new JSONParser(); File file = new File("saves/save.json"); FileReader fr = new FileReader(file); JSONObject root = (JSONObject) parser.parse(fr); JSONObject worldj = (JSONObject) root.get("world"); System.out.println(worldj);/*ww w.j a va2s .c o m*/ world.spawnFromJson(worldj); return world; }
From source file:autoancillarieslimited.parser.ParserUtil.java
public static Item parserItem(String dataJson) { try {//from ww w . jav a2 s. co m Item i = new Item(); 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 description = (String) jsonObject.get("P3"); int category = Integer.parseInt((String) jsonObject.get("P2")); double price = Double.parseDouble((String) jsonObject.get("P4")); String images = (String) jsonObject.get("P6"); // String imagesData i.setId(id); i.setName(name); i.setDescription(description); i.setPrice(price); i.setDate_Created(new Date()); TypeItem typeItemByID = ProductDAO.getInstance().getTypeItemByID(category); i.setTypeItem(typeItemByID); i.setType_ID(category); i.setImages(images); return i; } catch (Exception ex) { return null; } }
From source file:io.github.casnix.spawnerdropper.Config.java
public static int GetTNTChance() { try {// ww w. j a v a 2s.co 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:com.olhcim.engine.Mesh.java
public static Mesh loadMeshFile(String fileName) { //load and parse file JSONParser parser = new JSONParser(); Object obj = null;/* w ww . j a v a 2s . co m*/ try { obj = parser.parse(new FileReader(AppMain.class.getResource(fileName).getFile().replace("%20", " "))); } catch (IOException ex) { } catch (ParseException ex) { } JSONObject jObj = (JSONObject) obj; //load and convert to double array Object[] verticesObj = ((JSONArray) jObj.get("positions")).toArray(); double[] vertices = new double[verticesObj.length]; for (int i = 0; i < verticesObj.length; i++) { vertices[i] = (double) verticesObj[i]; } //load and convert to long array Object[] indicesObj = ((JSONArray) jObj.get("indices")).toArray(); long[] indices = new long[indicesObj.length]; for (int i = 0; i < indicesObj.length; i++) { indices[i] = (long) indicesObj[i]; } int verticesCount = vertices.length / 3; int facesCount = indices.length / 3; System.out.println("Vertices: " + verticesCount + " Faces: " + facesCount); Mesh mesh = new Mesh("", verticesCount, facesCount); // Filling the Vertices array of our mesh first for (int index = 0; index < verticesCount; index++) { float x = (float) vertices[index * 3]; float y = (float) vertices[index * 3 + 1]; float z = (float) vertices[index * 3 + 2]; mesh.vertices[index] = new Vector4f(x, y, z, 1); } // Then filling the Faces array for (int index = 0; index < facesCount; index++) { float a = (int) indices[index * 3]; float b = (int) indices[index * 3 + 1]; float c = (int) indices[index * 3 + 2]; mesh.faces[index] = new Vector3f(a, b, c); } return mesh; }
From source file:io.github.casnix.spawnerdropper.SpawnerStack.java
public static long GetSpawnersInService(String spawnerType) { try {//w ww .jav a 2 s .c o m // 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 number = (Long) jsonObj.get(spawnerType); // System.out.println("[SD DBG MSG] GSIS numberInServer("+number+")"); return number; } catch (ParseException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in GetSpawnersInService(String)"); e.printStackTrace(); return -1; } catch (FileNotFoundException e) { Bukkit.getLogger() .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerStack.json"); e.printStackTrace(); return -1; } catch (IOException e) { Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in GetSpawnersInService(String)"); e.printStackTrace(); return -1; } }
From source file:net.duckling.falcon.xss.JSONConfig.java
public static Whitelist parse(String filename) throws IOException, ParseException { String jsonString = FileUtils.readFileToString(new File(filename), "UTF-8"); JSONParser parser = new JSONParser(); Object obj = parser.parse(jsonString); if (obj instanceof JSONObject) { Whitelist whitelist = new Whitelist(); JSONObject config = (JSONObject) obj; addTags(whitelist, config);//w ww. j av a2s .c o m addProtocols(whitelist, config); return whitelist; } return Whitelist.none(); }
From source file:au.edu.unsw.cse.soc.federatedcloud.community.driven.cloudbase.util.LinkedObjectModelFactory.java
public static JSONObject generateObjectFromFile(File file) throws IOException, ParseException { JSONParser parser = new JSONParser(); JSONObject jsonObject = null;//from w w w.ja v a 2 s. c o m jsonObject = (JSONObject) parser.parse(new FileReader(file)); return jsonObject; }
From source file:freebase.api.FreebaseHelper.java
public static JSONArray getJSON(String fromDate, String toDate) { try {//from w w w .j a v a2s.co m properties.load(new FileInputStream("freebase.properties")); HttpTransport httpTransport = new NetHttpTransport(); HttpRequestFactory requestFactory = httpTransport.createRequestFactory(); JSONParser parser = new JSONParser(); String query = readQueryFromFile("queries/q1.json"); query = manipulateQuery(query, fromDate, toDate); GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread"); url.put("query", query); url.put("key", properties.get("API_KEY")); System.out.println("URL:" + url); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse httpResponse = request.execute(); JSONObject response = (JSONObject) parser.parse(httpResponse.parseAsString()); JSONArray results = (JSONArray) response.get("result"); Utils.writeDataIntoFile(results.toString() + "\n", FreebaseAPI.JSON_DUMP_FILE); return results; } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:de.keyle.mypet.npc.util.UpdateCheck.java
public static Optional<String> checkForUpdate() { try {/* ww w . ja va2s . com*/ String parameter = ""; parameter += "build=" + MyPetNpcVersion.getBuild(); // no data will be saved on the server String content = Util.readUrlContent("http://update.mypet-plugin.de/MyPet-NPC?" + parameter); JSONParser parser = new JSONParser(); JSONObject result = (JSONObject) parser.parse(content); if (result.containsKey("latest")) { return Optional.of(result.get("latest").toString()); } } catch (Exception ignored) { } return Optional.absent(); }