List of usage examples for org.json.simple JSONArray iterator
public Iterator<E> iterator()
From source file:JSONParser.JSONOperations.java
public ArrayList<String> parseWithColumnHeaderCri(JSONObject JSONObjectToParse, String columnHeaderCriteria, String rowName) {/*from w w w . ja va2 s . com*/ loggerObj.log(Level.INFO, "Inside parseWithColumnHeaderCri method"); ArrayList<String> caseID = null; try { JSONArray row = getRowsFromSupportapiJSON(JSONObjectToParse, rowName); Iterator<JSONObject> iterator = row.iterator(); while (iterator.hasNext()) { JSONArray rowIndex = (JSONArray) iterator.next().get("fl"); Iterator<JSONObject> innerIterator = rowIndex.iterator(); while (innerIterator.hasNext()) { JSONObject field = innerIterator.next(); String columnHeader = (String) field.get("val"); if (columnHeader.equals(columnHeaderCriteria)) { if (caseID == null) { caseID = new ArrayList<String>(); } caseID.add((String) field.get("content")); } } } } catch (Exception ex) { loggerObj.log(Level.SEVERE, "Issue in parsing the support api data to reports api format", ex); System.out.println("Issue in parsing the support api data to reports api format" + ex.toString()); } return caseID; }
From source file:JSONParser.JSONOperations.java
public JSONObject statusJSONToModuleCount(JSONArray statusJSONArray) { JSONObject moduleWiseCount = new JSONObject(); for (Iterator<JSONObject> ticketIterator = statusJSONArray.iterator(); ticketIterator.hasNext();) { JSONObject ticket = ticketIterator.next(); String moduleName = ticket.get("moduleName").toString(); if (!moduleWiseCount.containsKey(moduleName)) { moduleWiseCount.put(moduleName, 1); } else {//from www. ja v a2 s . c o m int existingCount = (Integer) moduleWiseCount.get(moduleName); moduleWiseCount.put(moduleName, existingCount + 1); } } return moduleWiseCount; }
From source file:JSONParser.JSONOperations.java
public ArrayList<String> parseTicketIdFromSub(JSONObject JSONObjectToParse, String rowName) { ArrayList<String> ticketIds = null; try {/*from www . java2 s. c o m*/ JSONArray row = getRowsFromSupportapiJSON(JSONObjectToParse, rowName); Iterator<JSONObject> iterator = row.iterator(); while (iterator.hasNext()) { JSONArray rowIndex = (JSONArray) iterator.next().get("fl"); Iterator<JSONObject> innerIterator = rowIndex.iterator(); while (innerIterator.hasNext()) { JSONObject field = innerIterator.next(); String columnHeader = (String) field.get("val"); if (columnHeader != null && columnHeader.equals("Subject")) { String columnValue = (String) field.get("content"); System.out.println("Column header:" + columnHeader + " column value" + columnValue); if (columnValue != null) { String[] splitString = columnValue.split("-"); if (splitString.length > 1) { if (ticketIds == null) { ticketIds = new ArrayList<>(); } String ticketId = splitString[0].trim(); boolean isNumber = isNumeric(ticketId); if (isNumber) { ticketIds.add(splitString[0].trim()); } } } } } } } catch (Exception ex) { loggerObj.log(Level.SEVERE, "Issue in parsing the support api data to reports api format", ex); System.out.println("Issue in parsing the support api data to reports api format" + ex.toString()); } return ticketIds; }
From source file:JSONParser.JSONOperations.java
public JSONObject ModuleVsStatusSummaryGenerator(JSONObject JOToParse, String[] statusString, String rowName, JSONObject parsedJO) {/*from www .jav a 2 s . co m*/ //JSONObject moduleCount = new JSONObject(); //JSONArray statusModuleCountArray = new JSONArray(); JSONArray row = getRowsFromSupportapiJSON(JOToParse, rowName); Iterator<JSONObject> rowIterator = row.iterator(); while (rowIterator.hasNext()) { JSONArray rowIndex = (JSONArray) rowIterator.next().get("fl"); Iterator<JSONObject> fieldIterator = rowIndex.iterator(); // int count = 0; String status = null; String moduleName = null; while (fieldIterator.hasNext()) { JSONObject field = fieldIterator.next(); String fieldVal = (String) field.get("val"); String fieldContent = (String) field.get("content"); if (fieldVal != null && fieldVal.equals("Status")) { for (String indiStringStatus : statusString) { if (fieldContent.equals(indiStringStatus) || fieldContent.equals("null")) { status = fieldContent; } } } if (fieldVal != null && fieldVal.equals("Module")) { if (fieldContent == null || fieldContent.equals("null")) { fieldContent = "Not Assigned"; } moduleName = fieldContent; } } if (status != null) { if (parsedJO == null) { parsedJO = new JSONObject(); } JSONObject moduleSummaryJO = (JSONObject) parsedJO.get(status); if (moduleSummaryJO == null) { moduleSummaryJO = new JSONObject(); JSONObject indiModuleJO = new JSONObject(); indiModuleJO.put("Count", 1); moduleSummaryJO.put(moduleName, indiModuleJO); parsedJO.put(status, moduleSummaryJO); } else { JSONObject indiModuleJO = (JSONObject) moduleSummaryJO.get(moduleName); if (indiModuleJO != null) { Integer moduleCount = (Integer) indiModuleJO.get("Count"); indiModuleJO.put("Count", moduleCount + 1); } else { indiModuleJO = new JSONObject(); indiModuleJO.put("Count", 1); } moduleSummaryJO.put(moduleName, indiModuleJO); parsedJO.put(status, moduleSummaryJO); } } } //System.out.println(statusModuleCountArray.toJSONString()); return parsedJO; }
From source file:com.thesmartweb.swebrank.JSONparsing.java
/** * Get meta info for a Youtube link/*w w w .j av a2s . c o m*/ * @param ventry the id of the Youtube video * @return a String with all the meta info about the youtube video */ public String GetYoutubeDetails(String ventry) { try { String apikey = "AIzaSyDLm-MfYHcbTHQO1S8ROX2rpvsqd5oYSRI"; String output = ""; URL link_ur = new URL("https://www.googleapis.com/youtube/v3/videos?id=" + ventry + "&key=" + apikey + "&part=snippet"); APIconn apicon = new APIconn(); String line = apicon.connect(link_ur); JSONParser parser = new JSONParser(); //Create the map Map json = (Map) parser.parse(line); // Get a set of the entries Set set = json.entrySet(); Iterator iterator = set.iterator(); Map.Entry entry = null; boolean flagfound = false; while (iterator.hasNext() && !flagfound) { entry = (Map.Entry) iterator.next(); if (entry.getKey().toString().equalsIgnoreCase("items")) { flagfound = true; } } JSONArray jsonarray = (JSONArray) entry.getValue(); Iterator iteratorarray = jsonarray.iterator(); flagfound = false; JSONObject get = null; while (iteratorarray.hasNext() && !flagfound) { JSONObject next = (JSONObject) iteratorarray.next(); if (next.containsKey("snippet")) { get = (JSONObject) next.get("snippet"); flagfound = true; } } String description = ""; String title = ""; if (flagfound) { if (get.containsKey("description")) { description = get.get("description").toString(); } if (get.containsKey("title")) { title = get.get("title").toString(); } output = description + " " + title; } Stopwords stopwords = new Stopwords(); output = stopwords.stop(output); return output; } catch (IOException | ArrayIndexOutOfBoundsException | ParseException ex) { Logger.getLogger(JSONparsing.class.getName()).log(Level.SEVERE, null, ex); String output = null; return output; } }
From source file:JSONParser.JSONOperations.java
public JSONArray SupJOToReportsJA(JSONObject JSONObjectToParse, JSONObject extraColumns, JSONObject SupTorepColumnChngHeader, String rowName) { try {//from www . j a v a 2s . c o m JSONArray issueMgrArray = new JSONArray(); JSONArray row = getRowsFromSupportapiJSON(JSONObjectToParse, rowName); Iterator<JSONObject> iterator = row.iterator(); while (iterator.hasNext()) { JSONObject issueMgrObj = new JSONObject(); JSONArray rowIndex = (JSONArray) iterator.next().get("fl"); Iterator<JSONObject> innerIterator = rowIndex.iterator(); if (extraColumns != null) { Set<String> extraColumnKeys = extraColumns.keySet(); for (Iterator it = extraColumnKeys.iterator(); it.hasNext();) { String key = it.next().toString(); issueMgrObj.put(key, extraColumns.get(key)); } } //issueMgrObj.put("Products", "Mobile Device Management (MDM)"); while (innerIterator.hasNext()) { JSONObject field = innerIterator.next(); Object columnHeader = field.get("val"); Object columnValue = field.get("content"); String setEmptyContent = "Not assigned"; if (SupTorepColumnChngHeader != null) { Set<String> suppHeaderChngKeySet = SupTorepColumnChngHeader.keySet(); for (Iterator itChange = suppHeaderChngKeySet.iterator(); itChange.hasNext();) { String suppHeaderChngKeys = itChange.next().toString(); if (columnHeader.toString().equals(suppHeaderChngKeys)) { if (columnValue != null) { if (columnValue.equals("null")) { issueMgrObj.put(SupTorepColumnChngHeader.get(suppHeaderChngKeys), setEmptyContent); } else { issueMgrObj.put(SupTorepColumnChngHeader.get(suppHeaderChngKeys), columnValue); } } else { issueMgrObj.put(SupTorepColumnChngHeader.get(suppHeaderChngKeys), setEmptyContent); loggerObj.log(Level.INFO, "Column value is null for the column header: " + columnHeader); } } else { if (columnValue != null) { if (columnValue.equals("null")) { issueMgrObj.put(columnHeader, setEmptyContent); } else { issueMgrObj.put(columnHeader, columnValue); } } else { issueMgrObj.put(columnHeader, setEmptyContent); } } } } else { if (columnValue != null) { issueMgrObj.put(columnHeader, columnValue); } else { issueMgrObj.put(columnHeader, setEmptyContent); } } } issueMgrArray.add(issueMgrObj); } loggerObj.log(Level.INFO, "Successfully parsed the support api data to reports api format"); //JSONObject result = new JSONObject(); //result.put("result", issueMgrArray); return issueMgrArray; } catch (Exception e) { loggerObj.log(Level.SEVERE, "Issue in parsing the support api data to reports api format", e); System.out.println("Issue in parsing the support api data to reports api format" + e.toString()); return null; } }
From source file:JSONParser.JSONOperations.java
public JSONObject MEMDMStatusWiseTicketGen(JSONArray ResponseFromServer, String rowName) { JSONObject statusJson = new JSONObject(); Iterator<JSONObject> jsonObjectItr = ResponseFromServer.iterator(); while (jsonObjectItr.hasNext()) { JSONArray row = getRowsFromSupportapiJSON((JSONObject) jsonObjectItr.next(), rowName); Iterator<JSONObject> iterator = row.iterator(); while (iterator.hasNext()) { JSONArray rowIndex = (JSONArray) iterator.next().get("fl"); Iterator<JSONObject> innerIterator = rowIndex.iterator(); JSONObject statusVal = new JSONObject(); String statusName = null; while (innerIterator.hasNext()) { JSONObject field = innerIterator.next(); if (field.get("val").toString().equals("Status")) { statusName = field.get("content").toString(); //To get all the status data; if (statusJson.get(statusName) == null) { statusJson.put(statusName, null); }/* w w w. j av a 2 s . co m*/ } if (field.get("val").toString().equals("Module")) { statusVal.put("moduleName", field.get("content").toString()); } if (field.get("val").toString().equals("Functionality")) { statusVal.put("functionalityName", field.get("content").toString()); } if (field.get("val").toString().equals("Issue Type")) { statusVal.put("issueType", field.get("content").toString()); } if (field.get("val").toString().equals("OS Platform")) { statusVal.put("osPlatform", field.get("content").toString()); } if (field.get("val").toString().equals("Created At")) { statusVal.put("createdAt", field.get("content").toString()); } } JSONArray currentStatusValue = (JSONArray) statusJson.get(statusName); if (currentStatusValue == null) { JSONArray newVal = new JSONArray(); newVal.add(statusVal); statusJson.put(statusName, newVal); } else { currentStatusValue.add(statusVal); } } } return statusJson; }
From source file:com.nubits.nubot.trading.wrappers.AllCoinWrapper.java
public ApiResponse getActiveOrdersImpl(CurrencyPair pair) { ApiResponse apiResponse = new ApiResponse(); boolean isGet = false; TreeMap<String, String> query_args = new TreeMap<>(); ArrayList<Order> orderList = new ArrayList<Order>(); String url = API_AUTH_URL; String method = API_OPEN_ORDERS; ApiResponse response = getQuery(url, method, query_args, true, isGet); if (response.isPositive()) { JSONObject httpAnswerJson = (JSONObject) response.getResponseObject(); JSONArray dataJson = (JSONArray) httpAnswerJson.get(TOKEN_DATA); if (dataJson == null) { ApiError apiError = errors.nullReturnError; apiResponse.setError(apiError); } else {/* w ww.java 2 s.com*/ for (Iterator<JSONObject> data = dataJson.iterator(); data.hasNext();) { Order order = parseOrder(data.next()); if (pair != null && !order.getPair().equals(pair)) { LOG.info("|" + order.getPair().toString() + "| = |" + pair.toString() + "|"); //we are only looking for orders with the specified pair. //the current order doesn't fill that need continue; } //check that completed orders aren't being returned if (order.isCompleted()) { continue; } orderList.add(order); } } apiResponse.setResponseObject(orderList); } else { apiResponse = response; } return apiResponse; }
From source file:com.thesmartweb.swebrank.JSONparsing.java
/** * Method to get the links from Google Search API (google gets every time only 10 results) * @param input the JSON response/* w ww.jav a 2 s . co m*/ * @return an array of the urls of the results */ public String[] GoogleJsonParsing(String input) { try { //Create a parser JSONParser parser = new JSONParser(); //Create a map JSONObject json = (JSONObject) parser.parse(input); //Get a set of the entries Set set = json.entrySet(); //Create an iterator Iterator iterator = set.iterator(); //Find the entry that contain the part of JSON that contains the link int i = 0; while (iterator.hasNext()) { Map.Entry entry = (Map.Entry) iterator.next(); if (entry.getKey().toString().equalsIgnoreCase("items")) { JSONArray jsonarray = (JSONArray) entry.getValue(); //find the key=link entry which contains the link Iterator iterator_jsonarray = jsonarray.iterator(); while (iterator_jsonarray.hasNext()) { JSONObject next = (JSONObject) iterator_jsonarray.next(); links[i] = next.get("link").toString(); i++; } } } return links; } catch (ParseException ex) { Logger.getLogger(JSONparsing.class.getName()).log(Level.SEVERE, null, ex); return links; } }
From source file:com.thesmartweb.swebrank.JSONparsing.java
public void DandelionParsing(String input, String query, boolean StemFlag) { try {//w ww. ja v a 2s. c om ent_avg_dand_score = 0.0; //Create a parser JSONParser parser = new JSONParser(); //Create the map Object parse = parser.parse(input); Map json = (Map) parser.parse(input); Set entrySet = json.entrySet(); Iterator iterator = entrySet.iterator(); Map.Entry entry = null; boolean flagfound = false; //we are going to search if we have semantic annotations while (iterator.hasNext() && !flagfound) { entry = (Map.Entry) iterator.next(); if (entry.getKey().toString().equalsIgnoreCase("annotations")) { flagfound = true; } } if (flagfound) { //if we have annotations we get the value JSONArray jsonarray = (JSONArray) entry.getValue(); Iterator iteratorarray = jsonarray.iterator(); flagfound = false; JSONObject get = null; while (iteratorarray.hasNext() && !flagfound) { JSONObject next = (JSONObject) iteratorarray.next(); if (next.containsKey("label")) { String entityString = next.get("label").toString().toLowerCase(); if (StemFlag) { String[] splitEntity = entityString.split(" "); entityString = ""; StemmerSnow stemmer = new StemmerSnow(); List<String> splitEntityList = stemmer.stem(Arrays.asList(splitEntity)); StringBuilder sb = new StringBuilder(); for (String s : splitEntityList) { sb.append(s.trim()); sb.append(" "); } entityString = sb.toString().trim(); } entitiesDand.add(entityString); } if (next.containsKey("categories")) { jsonarray = (JSONArray) next.get("categories"); for (int i = 0; i < jsonarray.size(); i++) { String categoryString = jsonarray.get(i).toString().toLowerCase(); if (StemFlag) { String[] splitEntity = categoryString.split(" "); categoryString = ""; StemmerSnow stemmer = new StemmerSnow(); List<String> splitEntityList = stemmer.stem(Arrays.asList(splitEntity)); StringBuilder sb = new StringBuilder(); for (String s : splitEntityList) { sb.append(s.trim()); sb.append(" "); } categoryString = sb.toString().trim(); } categoriesDand.add(categoryString); } } if (next.containsKey("confidence")) { ent_avg_dand_score = ent_avg_dand_score + Double.parseDouble(next.get("confidence").toString()); } } ent_avg_dand_score = ent_avg_dand_score / (double) entitiesDand.size(); ent_query_cnt_dand = 0; cat_query_cnt_dand = 0; ent_query_cnt_dand_whole = 0; cat_query_cnt_dand_whole = 0; query = query.toLowerCase(); String[] split = query.split("\\+"); if (StemFlag) { List<String> splitQuery = Arrays.asList(split); StemmerSnow stemmer = new StemmerSnow(); splitQuery = stemmer.stem(splitQuery); split = splitQuery.toArray(new String[splitQuery.size()]); } int ent_count = 0; for (String s : entitiesDand) { ent_count = 0; for (String splitStr : split) { if (s.contains(splitStr)) { ent_query_cnt_dand++; ent_count++; } } if (ent_count == split.length) { ent_query_cnt_dand_whole++; } } int cat_count = 0; for (String s : categoriesDand) { cat_count = 0; for (String splitStr : split) { if (s.contains(splitStr)) { cat_query_cnt_dand++; cat_count++; } } if (cat_count == split.length) { cat_query_cnt_dand_whole++; } } } } catch (ParseException ex) { Logger.getLogger(JSONparsing.class.getName()).log(Level.SEVERE, null, ex); } }