List of usage examples for org.json.simple.parser JSONParser JSONParser
JSONParser
From source file:com.oic.net.WebSocketListener.java
@OnWebSocketMessage public void onText(String message) { String method = ""; JSONObject json = new JSONObject(); try {// w ww. j a v a 2 s .co m json = (JSONObject) (new JSONParser().parse(message)); LOG.log(Level.INFO, "method : {0}", json.get("method")); //LOG.log(Level.INFO, "status : {0}", login); method = json.get("method").toString(); } catch (ParseException e) { LOG.log(Level.WARNING, "{0}", e); } /* ? */ selectMessage(method, json, this); }
From source file:info.usbo.skypetwitter.VK.java
private String findAttachment(JSONObject js) throws ParseException { String att = ""; System.out.println("att0" + js.get("id").toString()); if (js.get("attachments") != null) { System.out.println("att1"); JSONArray attach = (JSONArray) new JSONParser().parse(js.get("attachments").toString()); if (attach.size() > 0) { System.out.println("att2"); JSONObject attach1 = (JSONObject) new JSONParser().parse(attach.get(0).toString()); if (attach1.get("type") != null && "photo".equals(attach1.get("type").toString())) { System.out.println("att3"); JSONObject photo = (JSONObject) new JSONParser().parse(attach1.get("photo").toString()); if (photo.get("photo_604") != null) { att = photo.get("photo_604").toString(); }//from w w w . j a v a 2 s .c o m } } } return att; }
From source file:com.ge.research.semtk.sparqlX.parallel.SparqlParallelQueries.java
@SuppressWarnings("unchecked") public SparqlParallelQueries(String subqueriesJson, String subqueryType, boolean isSubqueryOptional, String columnsToFuseOn, String columnsToReturn) throws Exception { // parse the json array and build the subquery objects as we go gResultTable = null;/*from w ww . j a v a2 s. c o m*/ JSONArray subqueries = (JSONArray) (new JSONParser()).parse(subqueriesJson); this.subqueries = new ArrayList<>(subqueries.size()); for (int i = 0; i < subqueries.size(); i++) { JSONObject subquery = (JSONObject) subqueries.get(i); // let the constructor do the heavy lifting here this.subqueries.add(new SparqlSubquery(subquery)); } this.subqueryType = subqueryType; this.isSubqueryOptional = isSubqueryOptional; this.columnsToFuseOn = new LinkedHashSet<>(Arrays.asList(columnsToFuseOn.split(","))); this.columnsToReturn = new LinkedHashSet<>(Arrays.asList(columnsToReturn.split(","))); if (this.subqueries.size() == 0) { // this was completely invalid a call as we have no subqueries to process throw new Exception("subqueries json does not contain any subqueries."); } }
From source file:com.treasure_data.td_import.reader.JSONRecordReader.java
@Override public void configure(Task task) throws PreparePartsException { super.configure(task); sample(task);/* w w w. j a v a2 s . c om*/ try { reader = new BufferedReader(new InputStreamReader(task.createInputStream(conf.getCompressionType()), conf.getCharsetDecoder())); // create parser parser = new JSONParser(); } catch (IOException e) { throw new PreparePartsException(e); } }
From source file:de.elggconnect.elggconnectclient.webservice.AuthGetToken.java
@Override /**/*from w w w . j a v a2 s . c o m*/ * Run the AuthGetTokeb Web API Method */ public Long execute() { //Build url Parameter String String urlParameters = APIMETHOD + "&username=" + this.username + "&password=" + this.password; //Try to execute the API Method try { URL url = new URL(userAuthentication.getBaseURL()); URLConnection conn = url.openConnection(); //add user agent to the request header conn.setRequestProperty("User-Agent", USER_AGENT); conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(urlParameters); writer.flush(); String line; BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); //Read the response JSON StringBuilder text = new StringBuilder(); while ((line = reader.readLine()) != null) { text.append(line).append("\n"); } JSONObject json = (JSONObject) new JSONParser().parse(text.toString()); this.status = (Long) json.get("status"); if (this.status != -1L) { this.authToken = (String) json.get("result"); //Save the AuthToken userAuthentication.setAuthToken((String) json.get("result")); } writer.close(); reader.close(); } catch (Exception e) { System.err.println(e.getMessage()); } return this.status; }
From source file:admin.controller.ServletAddHtmlTemplate.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . j a v a2 s. c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { super.processRequest(request, response); response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); Layout layout = new Layout(); String fileName = null, filePath = null, fieldName = null, uploadPath = null, uploadType = null; StringBuffer string_buffer = new StringBuffer(); try { /* TODO output your page here. You may use following sample code. */ uploadPath = AppConstants.BASE_HTML_TEMPLATE_UPLOAD_PATH; BufferedReader reader = request.getReader(); String line = null; while ((line = reader.readLine()) != null) { string_buffer.append(line); } JSONParser parser = new JSONParser(); JSONObject json_html_template = null; json_html_template = (JSONObject) parser.parse(string_buffer.toString()); String type = (String) json_html_template.get("type"); // BufferedReader txtfile = new BufferedReader(new FileReader("c:\\test.txt")); String model_id = (String) json_html_template.get("model_id"); String model_name = (String) json_html_template.get("model_name"); String html_content = (String) json_html_template.get("html_content"); fileName = model_name + ".html"; filePath = uploadPath + File.separator + fileName; File uploadDir = new File(uploadPath); if (!uploadDir.exists()) { uploadDir.mkdirs(); } OutputStream htmlfile = new FileOutputStream(new File(filePath)); PrintStream printhtml = new PrintStream(htmlfile); layout.editModel(Integer.parseInt(model_id), fileName); printhtml.print(html_content); printhtml.close(); htmlfile.close(); out.write("true"); } catch (Exception ex) { logger.log(Level.SEVERE, "", ex); out.write(getSqlMethodsInstance().error); } }
From source file:Json.JsonCodes.java
public void jsonRead(String patchName) throws IOException, ParseException { JSONParser parser = new JSONParser(); JSONObject object = (JSONObject) parser.parse(new FileReader(patchName)); JSONArray arr = new JSONArray(); this.patch = (String) object.get("patch"); arr = (JSONArray) object.get("page"); for (int i = 0; i < arr.size(); i++) { this.pageList.add((String) arr.get(i)); }/*from w ww.j av a 2 s . com*/ System.out.println("Json.JsonWrite.jsonRead()"); }
From source file:org.kitodo.data.index.elasticsearch.type.WorkpieceTypeTest.java
@Test //problem with ordering of objects public void shouldCreateDocument() throws Exception { WorkpieceType workpieceType = new WorkpieceType(); JSONParser parser = new JSONParser(); Workpiece workpiece = prepareData().get(0); HttpEntity document = workpieceType.createDocument(workpiece); JSONObject workpieceObject = (JSONObject) parser.parse(EntityUtils.toString(document)); String actual = String.valueOf(workpieceObject.get("process")); String excepted = "1"; assertEquals("Workpiece value for process key doesn't match to given plain text!", excepted, actual); actual = String.valueOf(workpieceObject.get("properties")); excepted = "[{\"title\":\"first\",\"value\":\"1\"},{\"title\":\"second\",\"value\":\"2\"}]"; assertEquals("Workpiece value for properties key doesn't match to given plain text!", excepted, actual); workpiece = prepareData().get(1);//from w w w . jav a 2 s .c o m document = workpieceType.createDocument(workpiece); workpieceObject = (JSONObject) parser.parse(EntityUtils.toString(document)); actual = String.valueOf(workpieceObject.get("process")); excepted = "2"; assertEquals("Workpiece value for process key doesn't match to given plain text!", excepted, actual); actual = String.valueOf(workpieceObject.get("properties")); excepted = "[]"; assertEquals("Workpiece value for properties key doesn't match to given plain text!", excepted, actual); }
From source file:fr.itldev.koya.webscript.KoyaWebscript.java
/** * Extracts JSON POST data./* w w w . j av a 2 s. c o m*/ * * @param req * @return * @throws java.io.IOException */ public static Map<String, Object> getJsonMap(WebScriptRequest req) throws IOException { JSONParser parser = new JSONParser(); // TODO improve json POST reading try { return (JSONObject) parser.parse(req.getContent().getContent()); } catch (ParseException ex) { LOGGER.error(ex.getMessage(), ex); } return new HashMap<>(); }
From source file:iracing.webapi.SeasonQualifyingResultParser.java
public static long parse(String json, ItemHandler handler) { JSONParser parser = new JSONParser(); long output = 0; try {/*from w w w. j a v a 2 s . c o m*/ JSONObject root = (JSONObject) parser.parse(json); //{"m":{"1":"bestqualtime","2":"sublevel","3":"custrow","4":"maxlicenselevel","5":"rank","6":"helmcolor1","7":"displayname","8":"helmcolor2","9":"division","10":"custid","11":"helmcolor3","12":"clubid","13":"helmpattern","14":"pos","15":"rowcount","16":"bestqualtimeformatted","17":"rn"},"d":{"3":"-1","15":6,"r":[{"1":1465493,"2":"+2.36","4":18,"5":1,"6":255,"7":"Mitchell+Abrahall","8":118,"9":1,"10":25765,"11":108,"12":34,"13":62,"14":1,"16":"2%3A26.549","17":1},{"1":1490441,"2":"+3.43","4":15,"5":2,"6":255,"7":"John+Briggs","8":255,"9":5,"10":73770,"11":255,"12":34,"13":12,"14":2,"16":"2%3A29.044","17":2},{"1":1496234,"2":"+4.51","4":16,"5":3,"6":255,"7":"Stephen+Jenkins","8":96,"9":3,"10":68792,"11":112,"12":34,"13":22,"14":3,"16":"2%3A29.623","17":3},{"1":1502289,"2":"+3.45","4":14,"5":4,"6":240,"7":"Dirk+Benecke","8":130,"9":1,"10":84055,"11":255,"12":42,"13":63,"14":4,"16":"2%3A30.228","17":4},{"1":1513869,"2":"+2.73","4":10,"5":5,"6":44,"7":"Wayne+Stroh","8":240,"9":3,"10":88615,"11":185,"12":34,"13":56,"14":5,"16":"2%3A31.386","17":5},{"1":1548511,"2":"+2.61","4":17,"5":6,"6":80,"7":"Kyle+Young","8":249,"9":2,"10":72798,"11":240,"12":14,"13":21,"14":6,"16":"2%3A34.851","17":6}]}} Object o = root.get("d"); if (o instanceof JSONObject) { JSONObject d = (JSONObject) o; output = getLong(d, "15"); JSONArray arrayRoot = (JSONArray) d.get("r"); for (int i = 0; i < arrayRoot.size(); i++) { JSONObject r = (JSONObject) arrayRoot.get(i); SeasonQualifyingResult result = new SeasonQualifyingResult(); result.setBestQualifyingTime(getLong(r, "1")); result.setLicenseSubLevel(getString(r, "2")); result.setMaxLicenseLevel(getInt(r, "4")); result.setRank(getInt(r, "5")); result.setDriverName(getString(r, "7", true)); result.setDivision(getInt(r, "9")); result.setDriverCustomerId(getLong(r, "10")); result.setClubId(getInt(r, "12")); result.setPosition(getLong(r, "14")); result.setBestQualifyingTimeFormatted(getString(r, "16", true)); handler.onSeasonQualifyingResultParsed(result); } } } catch (ParseException ex) { Logger.getLogger(SeasonQualifyingResultParser.class.getName()).log(Level.SEVERE, null, ex); } return output; }