List of usage examples for org.json.simple.parser JSONParser parse
public Object parse(Reader in) throws IOException, ParseException
From source file:autoancillarieslimited.action.customer.UpdateProfileAction.java
private Customer parserCustomer(String dataJson) throws ParseException { Customer i = new Customer(); JSONParser parser = new JSONParser(); Object obj = parser.parse(dataJson); JSONObject jsonObject = (JSONObject) obj; int id = Integer.parseInt((String) jsonObject.get("P0")); String firstName = (String) jsonObject.get("P2"); String lastName = (String) jsonObject.get("P3"); String phoneNumber = (String) jsonObject.get("P5"); boolean gender = true; if (!((String) jsonObject.get("P6")).equals("0")) { gender = false;//ww w.j a va 2 s.com } String address = (String) jsonObject.get("P7"); String city = (String) jsonObject.get("P8"); String country = (String) jsonObject.get("P9"); i.setId(id); i.setFirstName(firstName); i.setLastName(lastName); i.setPhoneNumber(phoneNumber); i.setGender(gender); i.setAddress(address); i.setCity(city); i.setCountry(country); return i; }
From source file:com.example.austin.test.TextActivity.java
private void PrintOCRResponse(String jsonResponse) throws ParseException, IOException { JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(jsonResponse); JSONArray text = (JSONArray) jsonObj.get("OCRText"); String result = ""; for (int i = 0; i < text.size(); i++) { result = result + " " + text.get(i); }/* www.j a v a 2s .c o m*/ final TextView textView = (TextView) findViewById(R.id.textView); textView.setText(result); }
From source file:edu.ucsf.rbvi.CyAnimator.internal.io.LoadSessionListener.java
public void handleEvent(SessionLoadedEvent e) { // Reset CyAnimator FrameManager.reset();//w ww.j ava 2 s. c o m // Get the session CySession session = e.getLoadedSession(); /* System.out.println("Session: "+session); for (String s: session.getAppFileListMap().keySet()) { System.out.println(s+":"); for (File f: session.getAppFileListMap().get(s)) { System.out.println("File: "+f); } } */ if (!session.getAppFileListMap().containsKey("CyAnimator")) return; // System.out.println("We have animation information!"); // Ask the user if they want to load the frames? // try { File frameListFile = session.getAppFileListMap().get("CyAnimator").get(0); FileReader reader = new FileReader(frameListFile); BufferedReader bReader = new BufferedReader(reader); JSONParser parser = new JSONParser(); Object jsonObject = parser.parse(bReader); // For each root network, get the if (jsonObject instanceof JSONArray) { for (Object obj : (JSONArray) jsonObject) { try { FrameManager.restoreFramesFromSession(registrar, session, (JSONObject) obj); } catch (Exception ex) { ex.printStackTrace(); } } } bReader.close(); reader.close(); } catch (FileNotFoundException fnf) { System.out.println("File not found exception: " + fnf.getMessage()); } catch (IOException ioe) { System.out.println("IO exception: " + ioe.getMessage()); } catch (ParseException pe) { System.out.println("Unable to parse JSON file: " + pe.getMessage()); pe.printStackTrace(); } }
From source file:it.marcoberri.mbfasturl.helper.ConfigurationHelper.java
private ConfigurationHelper() { try {//from www. j av a 2 s . co m final URL main = getClass().getProtectionDomain().getCodeSource().getLocation(); final String path = URLDecoder.decode(main.getPath(), "utf-8"); final String webInfFolderPosition = new File(path).getPath(); final String webInfFolder = webInfFolderPosition.substring(0, webInfFolderPosition.indexOf("classes")); prop = new Properties(); prop.load(FileUtils.openInputStream(new File(webInfFolder + File.separator + "config.properties"))); final JSONParser parser = new JSONParser(); final Object obj = parser.parse(new FileReader(webInfFolder + File.separator + "cron.json")); final JSONObject jsonObject = (JSONObject) obj; ConfigurationHelper.cron = (JSONArray) jsonObject.get("cron"); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } catch (ParseException ex) { throw new RuntimeException(ex.getMessage(), ex); } }
From source file:kr.co.bitnine.octopus.testutils.MemoryDatabaseTest.java
@Test public void testImport() throws Exception { MemoryDatabase memDb = new MemoryDatabase("sample"); memDb.start();//from w w w . j av a2 s .c o m final String jsonFileName = "/sample.json"; memDb.importJSON(getClass(), jsonFileName); JSONParser jsonParser = new JSONParser(); JSONArray tables = (JSONArray) jsonParser .parse(new InputStreamReader(getClass().getResourceAsStream(jsonFileName))); assertEquals(2, tables.size()); Connection conn = memDb.getConnection(); Statement stmt = conn.createStatement(); JSONObject employee = (JSONObject) tables.get(0); ResultSet rs = stmt.executeQuery("SELECT * FROM \"employee\""); verifyTableEquals(employee, rs); rs.close(); JSONObject team = (JSONObject) tables.get(1); rs = stmt.executeQuery("SELECT * FROM \"team\""); verifyTableEquals(team, rs); rs.close(); stmt.close(); conn.close(); memDb.stop(); }
From source file:net.bashtech.geobot.BotManager.java
public static String postRemoteDataStrawpoll(String urlString) { String line = ""; try {/*from w w w. ja va 2 s. c o m*/ HttpURLConnection c = (HttpURLConnection) (new URL("http://strawpoll.me/api/v2/polls") .openConnection()); c.setRequestMethod("POST"); c.setRequestProperty("Content-Type", "application/json"); c.setRequestProperty("User-Agent", "CB2"); c.setDoOutput(true); c.setDoInput(true); c.setUseCaches(false); String queryString = urlString; c.setRequestProperty("Content-Length", Integer.toString(queryString.length())); DataOutputStream wr = new DataOutputStream(c.getOutputStream()); wr.writeBytes(queryString); wr.flush(); wr.close(); Scanner inStream = new Scanner(c.getInputStream()); while (inStream.hasNextLine()) line += (inStream.nextLine()); inStream.close(); System.out.println(line); try { JSONParser parser = new JSONParser(); Object obj = parser.parse(line); JSONObject jsonObject = (JSONObject) obj; line = (Long) jsonObject.get("id") + ""; } catch (Exception e) { e.printStackTrace(); } } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return line; }
From source file:com.greymemory.nab.Labels.java
public void Read(String file_name) { JSONParser parser = new JSONParser(); try {/*www . j a v a2 s . c o m*/ JSONObject root = (JSONObject) parser.parse(new FileReader(file_name)); SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); files.clear(); for (Object key : root.keySet()) { NAB_File f = new NAB_File(); f.file_name = (String) key; JSONArray file = (JSONArray) root.get(key); Iterator<JSONArray> iterator_file = file.iterator(); while (iterator_file.hasNext()) { JSONArray timestamps = iterator_file.next(); NAB_Anomaly a = new NAB_Anomaly(); a.start = format1.parse((String) timestamps.get(0)); a.stop = format1.parse((String) timestamps.get(1)); f.anomalies.add(a); } files.add(f); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (java.text.ParseException e) { e.printStackTrace(); } }
From source file:librarysystem.JSONHandlerElsiever.java
public List<Journal> parseJson() { // String elsevier = "http://api.elsevier.com/content/search/scidir?apiKey=" + KEY + "&query=ttl(neural)"; try {//from w w w . j av a 2 s . com //URL uri = new URL(elsevier); JSONParser parser = new JSONParser(); Object obj = parser.parse(readUrl(url)); JSONObject jsonObject = (JSONObject) obj; JSONObject searchObj = (JSONObject) jsonObject.get("search-results"); if (searchObj.containsKey("entry")) { JSONArray entryarray = (JSONArray) searchObj.get("entry"); Journal j = null;// new Journal(); blist = new ArrayList<Journal>(); //JSONArray autharray = null; for (int i = 0; i < entryarray.size(); i++) { j = new Journal(); JSONObject jnext = (JSONObject) entryarray.get(i); j.setID(0); j.setAbstract(jnext.get("prism:teaser").toString()); j.setPublication(jnext.get("prism:publicationName").toString()); j.settitle(jnext.get("dc:title").toString()); j.setisbn(jnext.get("prism:issn").toString()); j.setYear(jnext.get("prism:coverDisplayDate").toString()); String auths = ""; if (jnext.containsKey("authors")) { JSONObject jauthors = (JSONObject) jnext.get("authors"); JSONArray autharray = (JSONArray) jauthors.get("author"); for (int x = 0; x < autharray.size(); x++) { JSONObject anext = (JSONObject) autharray.get(x); auths = auths + " " + anext.get("given-name") + " " + anext.get("surname"); } j.setauthors(auths); } else j.setauthors(""); blist.add(j); } } } catch (Exception e) { e.printStackTrace(); } return blist; }
From source file:capabilities.DevicesSO.java
@Override public String adaptRole(String dbResult) throws Exception { // Variveis retornadas do WURFL em JSON String device_os;//from w ww .j av a 2s .c om String device_os_version; String model_name; String brand_name; String is_wireless_device; String is_tablet; String pointing_method; // Conversao do JSON de entrada para as variaveis respectivas JSONObject capabilities; JSONParser parser = new JSONParser(); capabilities = (JSONObject) parser.parse(dbResult); //JSONObject capabilities = (JSONObject) my_obj.get("capabilities"); System.out.println("\t" + capabilities); device_os = (String) capabilities.get("device_os"); device_os_version = (String) capabilities.get("device_os_version"); model_name = (String) capabilities.get("model_name"); brand_name = (String) capabilities.get("brand_name"); is_wireless_device = (String) capabilities.get("is_wireless_device"); is_tablet = (String) capabilities.get("is_tablet"); pointing_method = (String) capabilities.get("pointing_method"); // Criar um novo JSON e adicionar as informaes ele. JSONObject virtual = new JSONObject(); // Adicionar esse novo JSON ao JSON de entrada e retorn-lo capabilities.put("virtual", virtual); return capabilities.toJSONString(); }
From source file:info.mallmc.framework.util.ProfileLoader.java
private void addProperties(GameProfile profile) { String uuid = getUUID(skinOwner); try {/*w w w . j a v a2 s. c o m*/ // Get the name from SwordPVP URL url = new URL( "https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); URLConnection uc = url.openConnection(); uc.setUseCaches(false); uc.setDefaultUseCaches(false); uc.addRequestProperty("User-Agent", "Mozilla/5.0"); uc.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate"); uc.addRequestProperty("Pragma", "no-cache"); // Parse it String json = new Scanner(uc.getInputStream(), "UTF-8").useDelimiter("\\A").next(); JSONParser parser = new JSONParser(); Object obj = parser.parse(json); JSONArray properties = (JSONArray) ((JSONObject) obj).get("properties"); for (int i = 0; i < properties.size(); i++) { try { JSONObject property = (JSONObject) properties.get(i); String name = (String) property.get("name"); String value = (String) property.get("value"); String signature = property.containsKey("signature") ? (String) property.get("signature") : null; if (signature != null) { profile.getProperties().put(name, new Property(name, value, signature)); } else { profile.getProperties().put(name, new Property(value, name)); } } catch (Exception e) { L.ogError(LL.ERROR, Trigger.LOAD, "Failed to apply auth property", "Failed to apply auth property"); } } } catch (Exception e) { ; // Failed to load skin } }