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.ChangePasswordAction.java
public String execute() throws Exception { JSONParser parser = new JSONParser(); Object obj = parser.parse(data_request); JSONObject jsonObject = (JSONObject) obj; String currentPassword = (String) jsonObject.get("P0"); String password1 = (String) jsonObject.get("P1"); String password2 = (String) jsonObject.get("P2"); Customer customer = (Customer) map.get("USER"); if (!currentPassword.equals(customer.getPassWord())) { code = StringUtils.FAILD;//from www.j a va 2 s .c o m data_response = "Old Password is not correct"; return SUCCESS; } if (!password1.equals(password2)) { code = StringUtils.FAILD; data_response = "Old Password is not correct"; } customer.setPassWord(password2); CustomerDAO.getInstance().update(customer); map.put("USER", customer); code = 400; data_response = "Change Password Success"; return SUCCESS; }
From source file:com.au.splashinc.JControl.Load.JsonLoader.java
@Override public void LoadConfig() { JSONParser parser = new JSONParser(); try {/*from w ww . j a v a2s.c o m*/ Object obj = parser.parse(new FileReader(location)); JSONObject jsonObject = (JSONObject) obj; //Do stuff probably in another class } catch (IOException | ParseException ex) { Logger.getLogger(JsonLoader.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.shazam.dataengineering.pipelinebuilder.DeploymentLog.java
public DeploymentLog(String json) { try {/*www . j a v a 2 s . c o m*/ JSONParser jsonParser = new JSONParser(); log = (JSONObject) jsonParser.parse(json); } catch (ParseException e) { parseException = e; } }
From source file:controller.JsonController.java
public ArrayList<JsonModel> ReadJsonCalc() throws FileNotFoundException, IOException, ParseException { FileInputStream fstream = new FileInputStream("gistfile1.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine;/*from w ww. j ava2 s .c om*/ ArrayList<JsonModel> result = new ArrayList<>(); JsonModel model; double L1, G1, L2, G2; //Read File Line By Line while ((strLine = br.readLine()) != null) { model = new JsonModel(); JSONParser parser = new JSONParser(); Object obj = parser.parse(strLine); JSONObject jsonObject = (JSONObject) obj; model.setLatitude((double) Double.parseDouble((String) jsonObject.get("latitude"))); model.setLongitude((double) Double.parseDouble((String) jsonObject.get("longitude"))); model.setUserIid((int) Integer.parseInt((String) jsonObject.get("user_id").toString())); model.setName(((String) jsonObject.get("name"))); L1 = Math.toRadians(model.getLatitudeDefault()); G1 = Math.toRadians(model.getLongitudeDefault()); L2 = Math.toRadians(model.getLatitude()); G2 = Math.toRadians(model.getLongitude()); // do the spherical trig calculation double angle = Math.acos(Math.sin(L1) * Math.sin(L2) + Math.cos(L1) * Math.cos(L2) * Math.cos(G1 - G2)); // convert back to degrees angle = Math.toDegrees(angle); // each degree on a great circle of Earth is 69.1105 miles double distance = (69.1105 * angle) * 1.609344; if (distance <= 100) result.add(model); } Collections.sort(result); return result; }
From source file:kr.co.bitnine.octopus.schema.metamodel.OctopusMetaModelDataSource.java
public OctopusMetaModelDataSource(MetaDataSource metaDataSource) { super(metaDataSource); LOG.debug("create OctopusMetaModelDataSource. dataSourceName: " + metaDataSource.getName()); JSONParser jsonParser = new JSONParser(); try {/*from w ww . ja va 2 s .co m*/ connectionInfo = (JSONObject) jsonParser.parse(metaDataSource.getConnectionString()); } catch (ParseException ignore) { /* * NOTE: parse() never fail, because ADD DATASOURCE... succeeded. * This assumption is NOT preferable. */ } ImmutableMap.Builder<String, Schema> builder = ImmutableMap.builder(); for (MetaSchema metaSchema : metaDataSource.getSchemas()) builder.put(metaSchema.getName(), new OctopusMetaModelSchema(metaSchema, this)); setSubSchemaMap(builder.build()); }
From source file:mobilebank.Json.java
public JSONObject getJson(String url) throws ParseException { HttpPost httppost = new HttpPost(baseUrl + url); // Depends on your web service httppost.setHeader("Content-type", "application/x-www-form-urlencoded"); InputStream inputStream = null; String result = null;//from w w w . j a va2s.c o m try { HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); inputStream = entity.getContent(); // json is UTF-8 by default BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } result = sb.toString(); } catch (Exception e) { // Oops } finally { try { if (inputStream != null) inputStream.close(); } catch (Exception squish) { } } JSONParser parser = new JSONParser(); JSONObject jObject = (JSONObject) parser.parse(result); return jObject; }
From source file:com.justgiving.raven.kissmetrics.schema.KissmetricsJsonToSchemaMapper.java
@Override public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String s = value.toString();/*from ww w .jav a2s . c o m*/ JSONParser jsonParser = new JSONParser(); try { JSONObject jsonObject = (JSONObject) jsonParser.parse(s); Set<String> keyset = jsonObject.keySet(); String jsonValue = ""; for (String jsonkey : keyset) { jsonValue = (String) jsonObject.get(jsonkey).toString(); if (jsonValue == null || jsonValue == "") { jsonValue = ""; } String lenValue = String.valueOf(jsonValue.length()); if (lenValue == null || lenValue == "") { lenValue = "0"; } context.write(new Text(jsonkey), new Text("1\t" + lenValue)); } } catch (ParseException e) { e.printStackTrace(); } }
From source file:org.kitodo.data.index.elasticsearch.type.DocketTypeTest.java
@Test public void shouldCreateDocument() throws Exception { DocketType docketType = new DocketType(); Docket docket = prepareData().get(0); HttpEntity document = docketType.createDocument(docket); JSONParser parser = new JSONParser(); JSONObject docketObject = (JSONObject) parser.parse(EntityUtils.toString(document)); String actual = String.valueOf(docketObject.get("name")); String excepted = "default"; assertEquals("Docket value for name key doesn't match to given plain text!", excepted, actual); actual = String.valueOf(docketObject.get("file")); excepted = "docket.xsl"; assertEquals("Docket value for file key doesn't match to given plain text!", excepted, actual); }
From source file:com.klarna.checkout.Handler.java
/** * Parse the payload.//ww w. java 2s. c o m * * @param payload JSON payload to parse. * * @throws IOException if parse was unsuccessful. */ protected void parsePayload(final String payload) throws IOException { try { JSONParser jsonParser = new JSONParser(); Object json = jsonParser.parse(payload); resource.parse((HashMap<String, Object>) json); } catch (ParseException ex) { // Interface dictates strict exception types. throw new IOException(ex); } }
From source file:Connector.Connector.java
private void setCredentials() { Map<String, String> env = System.getenv(); if (env.containsKey("VCAP_SERVICES")) { try {/* ww w . j a v a 2 s . c om*/ JSONParser parser = new JSONParser(); JSONObject vcap = (JSONObject) parser.parse(env.get("VCAP_SERVICES")); JSONObject service = null; for (Object key : vcap.keySet()) { String keyStr = (String) key; if (keyStr.toLowerCase().contains("tradeoff_analytics")) { service = (JSONObject) ((JSONArray) vcap.get(keyStr)).get(0); break; } } if (service != null) { JSONObject creds = (JSONObject) service.get("credentials"); String username = (String) creds.get("username"); String password = (String) creds.get("password"); this.username = username; this.password = password; System.out.println(username); System.out.println(password); } } catch (Exception e) { e.printStackTrace(System.err); } } }