List of usage examples for org.json.simple.parser JSONParser JSONParser
JSONParser
From source file:net.bashtech.geobot.JSONUtil.java
public static Long krakenViewers(String channel) { try {/*from w w w. ja v a 2 s . c o m*/ JSONParser parser = new JSONParser(); Object obj = parser .parse(BotManager.getRemoteContent("https://api.twitch.tv/kraken/streams/" + channel)); JSONObject jsonObject = (JSONObject) obj; JSONObject stream = (JSONObject) (jsonObject.get("stream")); if (stream == null) return (long) 0; Long viewers = (Long) stream.get("viewers"); return viewers; } catch (Exception ex) { System.out.println("Kraken Viewers isn't working"); return (long) 0; } }
From source file:DelProductWS.DelProductWS.java
@WebMethod(operationName = "delProduct") public int delProduct(@WebParam(name = "access_token") String access_token, @WebParam(name = "product_id") String product_id) throws IOException, ParseException { int status = 0; Connection dbConn = DbConnectionManager.getConnection(); String targetIS = "ValidateToken"; String urlParameters = "access_token=" + access_token; HttpURLConnection urlConn = UrlConnectionManager.doReqPost(targetIS, urlParameters); String resp = UrlConnectionManager.getResponse(urlConn); JSONParser parser = new JSONParser(); JSONObject obj = (JSONObject) parser.parse(resp); String statusResp = (String) obj.get("status"); String username = (String) obj.get("username"); switch (statusResp) { case "valid": try {/*from w w w .j a va 2 s . c om*/ String query = "DELETE FROM catalogue WHERE product_id='" + product_id + "'"; PreparedStatement ps = dbConn.prepareStatement(query); int i = ps.executeUpdate(); } catch (SQLException ex) { System.out.println("Inser to database failed: An Exception has occurred! " + ex); } finally { if (dbConn != null) { try { dbConn.close(); } catch (SQLException e) { System.out.println(e); } dbConn = null; } } status = 1; break; case "non-valid": status = 2; break; default: status = 3; break; } return status; }
From source file:info.pancancer.arch3.utils.Utilities.java
public static JSONObject parseJSONStr(String jsonStr) { JSONObject data = null;// www .j av a 2 s.c o m JSONParser parser = new JSONParser(); try { data = (JSONObject) parser.parse(jsonStr); } catch (ParseException ex) { throw new RuntimeException(ex); } return data; }
From source file:matrix.CreateUserList.java
public void tweetsToUserList() throws FileNotFoundException, UnsupportedEncodingException, IOException, ParseException { File fout = new File(userListPathOutput); FileOutputStream fos = new FileOutputStream(fout); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); BufferedReader inputTW = new BufferedReader( new InputStreamReader(new FileInputStream(tweetsJsonInput), "ISO-8859-9")); ArrayList userList = new ArrayList(); JSONParser jsonParser = new JSONParser(); JSONArray jsonArray = (JSONArray) jsonParser.parse(inputTW); int sayac = 0; for (Object obj : jsonArray) { JSONObject tweet = (JSONObject) obj; JSONObject user = (JSONObject) tweet.get("user"); // String userID = user.get("id").toString(); // String userName = user.get("name").toString(); String userID = user.get("id").toString(); String userName = user.get("name").toString(); if (userList.contains(userID) == false) { userList.add(userID);/*from w w w . j ava 2 s.c o m*/ bw.write(userID + "," + userName); bw.newLine(); sayac++; } } System.out.println(sayac); }
From source file:ClubImpl.java
public String getAboutUs() { JSONParser parser = new JSONParser(); Object obj = null;/*from www. j a v a 2 s. com*/ try { File f = new File("."); System.out.println(f.getAbsolutePath()); File relative = new File("AboutUs.json"); obj = parser.parse(new FileReader(relative)); } catch (Exception ex) { Logger.getLogger(ClubImpl.class.getName()).log(Level.SEVERE, null, ex); } JSONObject jsonObject = (JSONObject) obj; return jsonObject.toJSONString(); }
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 ww. j ava2 s. c om 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; }
From source file:com.mycompany.test.Jaroop.java
/** * @param response response string which is in JSON format. * This method parses the JSON formatted data and prints the output. *//*from w w w . j a v a 2 s . com*/ private static void parseJSON(String response) { try { JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject) jsonParser.parse(response); String output = jsonObject.get("extract").toString(); System.out.print(output); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:autoancillarieslimited.action.customer.LoginCustomerAction.java
public String execute() { try {/* w w w. ja va 2 s.c o 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:com.serena.rlc.provider.servicenow.domain.Incident.java
public static List<Incident> parse(String options) { List<Incident> crList = new ArrayList<>(); JSONParser parser = new JSONParser(); try {/*from w w w . j a va 2 s . c o m*/ Object parsedObject = parser.parse(options); JSONArray jsonArray = (JSONArray) getJSONValue((JSONObject) parsedObject, "result"); for (Object object : jsonArray) { Incident iObj = parseSingle((JSONObject) object); crList.add(iObj); } } catch (ParseException e) { logger.error("Error while parsing input JSON - " + options, e); } return crList; }
From source file:net.modsec.ms.connector.ConnRequestHandler.java
/** * Parses the incomming requests and process it accordingly. * @param msg// ww w . ja v a2s . c o m */ public static void onConRequest(String msg) { log.info("onConRequest called :" + msg); JSONParser parser = new JSONParser(); try { Object obj = parser.parse(msg); JSONObject json = (JSONObject) obj; String action = (String) json.get("action"); if (action.equals("start")) { onStartRequest(json); } else if (action.equals("stop")) { onStopRequest(json); } else if (action.equals("restart")) { onRestartRequest(json); } else if (action.equals("status")) { onStatusRequest(json); } else if (action.equals("readMSConfig")) { onReadMSConfig(json); } else if (action.equals("writeMSConfig")) { onWriteMSConfig(json); } else if (action.equals("deployRules")) { onDeployMSRules(json); } } catch (ParseException e) { e.printStackTrace(); } }