List of usage examples for org.json.simple JSONArray toJSONString
public String toJSONString()
From source file:importer.handler.post.stages.SAXSplitter.java
public static void main(String[] args) { if (args.length == 1) { File f = new File(args[0]); byte[] data = new byte[(int) f.length()]; try {//from w w w . j a v a 2s.c o m FileInputStream fis = new FileInputStream(f); fis.read(data); SAXSplitter ss = new SAXSplitter(); JSONArray jArr = ss.scan(new String(data, "UTF-8")); String jStr = jArr.toJSONString(); System.out.println(jStr.replaceAll("\\\\/", "/")); } catch (Exception e) { System.out.println(e.getMessage()); } } }
From source file:me.prokopyl.storagemonitor.httpserver.HTTPResponse.java
static public String ToJSONString(Object object) { if (object instanceof JSONAware) { return ((JSONAware) object).toJSONString(); } else {/*from w ww.j a v a 2 s.co m*/ JSONArray array = new JSONArray(); array.add(object); return array.toJSONString(); } }
From source file:com.rmtheis.yandtran.YandexTranslatorAPI.java
private static String[] jsonObjValToStringArr(final String inputString, final String subObjPropertyName) throws Exception { JSONObject jsonObj = (JSONObject) JSONValue.parse(inputString); JSONArray jsonArr = (JSONArray) jsonObj.get(subObjPropertyName); return jsonArrToStringArr(jsonArr.toJSONString(), null); }
From source file:com.p000ison.dev.simpleclans2.util.JSONUtil.java
public static String collectionToJSON(Collection collection) { if (collection == null) { return null; }/*ww w . j a va2 s . co m*/ JSONArray array = new JSONArray(); array.addAll(collection); return array.toJSONString(); }
From source file:cat.tv3.eng.rec.recomana.lupa.visualization.TextsResumeToJson.java
private static void saveResults(JSONArray recomendations, String id) { Writer out;/* w w w . j a v a 2s. c om*/ try { out = new BufferedWriter(new OutputStreamWriter( new FileOutputStream("data_toVisualize/data_resume/resume_" + id + ".json"), "UTF-8")); try { out.write(recomendations.toJSONString()); out.close(); } catch (IOException e) { e.printStackTrace(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:com.p000ison.dev.simpleclans2.util.JSONUtil.java
public static String clansToJSON(Collection<Clan> clans) { if (clans == null) { return null; }// w w w .ja va2 s. c om JSONArray array = new JSONArray(); for (Clan clan : clans) { array.add(clan.getID()); } return array.toJSONString(); }
From source file:cat.tv3.eng.rec.recomana.lupa.visualization.RecommendationToJson.java
private static void saveResults(JSONArray recomendations, String id) { Writer out;//from ww w.ja v a 2 s. c om try { out = new BufferedWriter(new OutputStreamWriter( new FileOutputStream("data_toVisualize/data_recommendation/recommendation_" + id + ".json"), "UTF-8")); try { out.write(recomendations.toJSONString()); out.close(); } catch (IOException e) { e.printStackTrace(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:com.criticalsoftware.mobics.presentation.util.GeolocationUtil.java
public static List<PlaceDTO> getAddressFromText(String address) throws UnsupportedEncodingException { List<PlaceDTO> results = new ArrayList<PlaceDTO>(); address = URLEncoder.encode(address, Configuration.INSTANCE.getUriEnconding()); String url = MessageFormat.format(SEARCH_URL, Configuration.INSTANCE.getGeolocationServer(), address, Configuration.INSTANCE.getGeolocationServerAllowedCountries(), Configuration.INSTANCE.getMaxResults()); HttpMethod method = new GetMethod(url); try {//from w w w . ja va 2 s .c o m if (LOGGER.isTraceEnabled()) { LOGGER.trace("Making search location call to: {}", url); } int statusCode = new HttpClient().executeMethod(method); if (statusCode == HttpStatus.SC_OK) { byte[] responseBody = readResponse(method); JSONArray jsonArray = (JSONArray) new JSONParser().parse(new String(responseBody)); if (LOGGER.isTraceEnabled()) { LOGGER.trace(jsonArray.toJSONString()); } @SuppressWarnings("unchecked") Iterator<JSONObject> it = jsonArray.iterator(); while (it.hasNext()) { JSONObject place = it.next(); results.add(new PlaceDTO((String) place.get(DISPLAY_NAME), (String) place.get(LATITUDE_NAME), (String) place.get(LONGITUDE_NAME))); } } else { LOGGER.warn("Recived a HTTP status {}. Response was not good from {}", statusCode, url); } } catch (HttpException e) { LOGGER.error("Error while making call.", e); } catch (IOException e) { LOGGER.error("Error while reading the response.", e); } catch (ParseException e) { LOGGER.error("Error while parsing json response.", e); } return results; }
From source file:edu.usc.polar.CompositeNERAgreementParser.java
public static void CompositeNER(String doc, String args[]) { try {// w w w . j ava 2 s .co m String text; AutoDetectParser parser = new AutoDetectParser(); BodyContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); InputStream stream = new FileInputStream(doc); // System.out.println(stream.toString()); parser.parse(stream, handler, metadata); // return handler.toString(); text = handler.toString(); String metaValue = metadata.toString(); System.out.println(metaValue + "Desc:: " + metadata.get("description")); String[] example = new String[1]; example[0] = text; String name = doc.replace("C:\\Users\\Snehal\\Documents\\TREC-Data\\Data", "polar.usc.edu"); name = name.replace("\\", "."); Map<String, Set<String>> list = getCoreNLP(text); Map<String, Set<String>> list1 = getOpenNLP(text); Map<String, Set<String>> list2 = getNLTKRest(text); Set<String> NLTKRestSet = combineSets(list2); Set<String> coreNLPSet = combineSets(list); Set<String> openNLPSet = combineSets(list1); /* System.out.println("list coreNLP"+JSONStringify(coreNLPSet).toJSONString()); System.out.println("list openNLPSet"+openNLPSet); System.out.println("list NLTKRestSet"+NLTKRestSet); */ JSONObject jsonObj = new JSONObject(); jsonObj.put("DOI", name); jsonObj.put("OpenNLP", JSONStringify(openNLPSet)); jsonObj.put("NLTKRest", JSONStringify(NLTKRestSet)); jsonObj.put("CoreNLP", JSONStringify(coreNLPSet)); Set<String> union = new HashSet(); union.addAll(NLTKRestSet); union.addAll(coreNLPSet); union.addAll(openNLPSet); jsonObj.put("Union", JSONStringify(union)); Set<String> intersection = new HashSet(); intersection.addAll(union); intersection.retainAll(coreNLPSet); intersection.retainAll(openNLPSet); intersection.retainAll(NLTKRestSet); jsonObj.put("Agreement", JSONStringify(intersection)); /* System.out.println(name+"\n"+openNLPSet.size()+openNLPSet.toString()+ "\n"+coreNLPSet.size()+coreNLPSet.toString()+ "\n"+NLTKRestSet.size()+NLTKRestSet.toArray()+ "\n"+intersection.size()+intersection.toArray()+ "\n"+union.size()+union.toArray()); */ //jsonObj.put("metadata",metaValue.replaceAll("\\s\\s+|\n|\t"," ")); jsonArray.add(jsonObj); if (intersection.size() > 0) { jsonAgree.add(jsonObj); JSONArray jArr = new JSONArray(); jArr.add(jsonObj); metadata.add("CompositeNER", jArr.toJSONString()); } } catch (Exception e) { System.out.println("ERROR : OpenNLP" + "|File Name" + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString()); } }
From source file:jQuery.PRIMO.Record.java
/** * Resolve dedup record string./*from www . ja va 2 s .co m*/ * * @param dedupID the dedup id * @param request the request * @return a JSON array of record id's */ public static String resolveDedupRecord(String dedupID, HttpServletRequest request) { JSONArray obj = new JSONArray(); try { if ((dedupID != null) && (dedupID.length() > 0)) { obj.addAll(Helpers.resolveDedupRecord(dedupID, request)); } } catch (Exception e) { e.printStackTrace(); obj.add(e.getMessage()); } return obj.toJSONString(); }