List of usage examples for org.json.simple.parser JSONParser parse
public Object parse(Reader in) throws IOException, ParseException
From source file:com.polopoly.tools.minifier.FileMapConstructor.java
public Map<String, List<String>> decodeFiles(String json) throws BadJsonException { Map<String, List<String>> result = new HashMap<String, List<String>>(); JSONParser parser = new JSONParser(); try {// www . j ava2 s.c om Object parsed = parser.parse(json); if (parsed instanceof JSONObject) { JSONObject fileMap = (JSONObject) parsed; for (Object fileObj : fileMap.keySet()) { String filename = fileObj.toString(); Object parsedArray = fileMap.get(fileObj); if (parsedArray instanceof JSONArray) { result.put(filename, getFilesFromMap((JSONArray) parsedArray)); } } } else { throw new BadJsonException("Top level object not a string"); } } catch (ParseException e) { throw new BadJsonException(e); } return result; }
From source file:autoancillarieslimited.action.cart.ChangeStatusOrderAction.java
public String execute() throws Exception { try {// w ww . j a va 2 s .c o m JSONParser parser = new JSONParser(); Object obj = parser.parse(data_request); JSONObject jsonObject = (JSONObject) obj; int id_order = Integer.parseInt((String) jsonObject.get("P0")); int status = Integer.parseInt((String) jsonObject.get("P1")); PurchaseOrder byID = PurchaseOrderDAO.getInstance().getByID(id_order, PurchaseOrder.class); if (byID != null) { byID.setStatus(status); PurchaseOrderDAO.getInstance().update(byID); code = 400; } else { data_response = "Login faild. Check Email or Password !"; code = 405; } } catch (Exception ex) { data_response = ex.getMessage(); code = 405; } return SUCCESS; }
From source file:com.AandC.Power.MainActivity.java
void ReviveJson() { if (Files.getFiles()[1].exists()) { try {/*from ww w .j a v a2 s . co m*/ JSONParser parser = new JSONParser(); Object obj = parser.parse(new FileReader(Files.FileSys[1])); JSONObject jsonObject = (JSONObject) obj; UserInfo.setName(jsonObject.get("name").toString()); UserInfo.setAge(Integer.parseInt(jsonObject.get("age").toString())); UserInfo.setDen(jsonObject.get("den").toString()); UserInfo.Update(); } catch (Exception e) { e.printStackTrace(); (new MsgBox("Problem", "There was a problem loading your information. " + "You will have to restart", this)) .Show(); } } }
From source file:org.kitodo.data.elasticsearch.index.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 actual = (JSONObject) parser.parse(EntityUtils.toString(document)); JSONObject excepted = (JSONObject) parser.parse("{\"title\":\"default\",\"file\":\"docket.xsl\"}"); assertEquals("Docket JSONObject doesn't match to given JSONObject!", excepted, actual); }
From source file:edu.asu.msse.gnayak2.main.JSONFileReader.java
public JSONFileReader() { JSONParser jsonParser = new JSONParser(); try {/*from w ww .ja v a 2 s . c om*/ this.jsonArray = (JSONArray) jsonParser.parse(new FileReader(StringConstants.JSON_FILE_NAME)); } catch (Exception e) { System.out.println("some ex"); } }
From source file:autoancillarieslimited.action.employee.CheckLogin.java
public String execute() throws Exception { JSONParser parser = new JSONParser(); Object obj = parser.parse(data_request); JSONObject jsonObject = (JSONObject) obj; String user = (String) jsonObject.get("P0"); String pass = (String) jsonObject.get("P1"); Employee checkLogin = EmployeeDAO.getInstance().checkLogin(user, pass); Admin checkLoginAdmin = EmployeeDAO.getInstance().checkLoginAdmin(user, pass); if (checkLoginAdmin != null) { code = 401;/*from w w w.j a va 2s. co m*/ map.put("USER-ADMIN", checkLoginAdmin); return SUCCESS; } else if (checkLogin != null) { code = 400; map.put("USER-EMPLOYEE", checkLogin); } else { code = 405; data_response = "Login Faild. Check your email or password!"; } return SUCCESS; }
From source file:autoancillarieslimited.action.customer.LoginCustomerAction.java
public String execute() { try {//from w ww. ja va 2s.co m JSONParser parser = new JSONParser(); Object obj = parser.parse(data_request); JSONObject jsonObject = (JSONObject) obj; String email = (String) jsonObject.get("P0"); String password = (String) jsonObject.get("P1"); Customer checkLogin = CustomerDAO.getInstance().checkLogin(email, password); if (checkLogin != null) { map.put("USER", checkLogin); code = 400; } else { data_response = "Login faild. Check Email or Password !"; code = 405; } } catch (Exception ex) { data_response = ex.getMessage(); code = 405; } return SUCCESS; }
From source file:de.hstsoft.sdeep.Configuration.java
public void load() throws IOException, ParseException { Reader reader = new BufferedReader(new FileReader(configFile)); JSONParser jsonParser = new JSONParser(); JSONObject json = (JSONObject) jsonParser.parse(reader); saveGamePath = json.get(PREF_SAVEGAME_PATH).toString(); autorefresh = Boolean.parseBoolean(json.get(PREF_AUTOREFRESH).toString()); reader.close();/*from ww w . ja v a2s .c o m*/ }
From source file:ch.newscron.newscronjsp.DecodeDataUtils.java
public String showURLData() throws ParseException, Exception { String url = Encryption.decode(encodedURL.trim()); if (url == null) { return "<p> Invalid URL </p>"; }/*w ww.j av a2 s.c om*/ else if (url.equals("")) { return "<p> Corrupt URL - invalid data! </p>"; } else { JSONParser parser = new JSONParser(); JSONObject newobj = (JSONObject) parser.parse(url); customerId = newobj.get("custID").toString(); String rew1 = newobj.get("rew1").toString(); String rew2 = newobj.get("rew2").toString(); String val = newobj.get("val").toString(); return "<table border='0' class=\"center\"> " + "<tr> " + " <td> custID: </td> <td>" + customerId + "</td> " + "</tr> " + "<tr> " + " <td> rew1: </td> <td>" + rew1 + "</td> " + "</tr> " + "<tr> " + " <td> rew2: </td> <td>" + rew2 + "</td> " + "</tr> " + "<tr> " + " <td> val: </td> <td>" + val + "</td> " + "</tr> " + "</table>"; } }
From source file:jcine.AsientosClient.java
public Asiento[] getAsientos() throws IOException, ParseException { HttpURLConnection conn = (HttpURLConnection) entryPoint.openConnection(); conn.setRequestMethod("GET"); conn.setDoOutput(true);/*from w w w . j av a 2s .co m*/ StringBuilder builder = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); String line; while ((line = reader.readLine()) != null) { builder.append(line); } JSONParser parser = new JSONParser(); JSONArray list = (JSONArray) parser.parse(builder.toString()); Asiento[] result = new Asiento[list.size()]; for (int i = 0; i < list.size(); i++) { JSONObject obj = (JSONObject) list.get(i); String name = (String) obj.get("numero"); Long posX = (Long) obj.get("posicionX"); Long posY = (Long) obj.get("posicionY"); result[i] = new Asiento(name, posX.intValue(), posY.intValue()); } return result; }