List of usage examples for org.json.simple JSONObject put
V put(K key, V value);
From source file:com.flaptor.indextank.api.resources.Search.java
@SuppressWarnings("unchecked") private static Map<String, Map<String, Integer>> toFacets(Map<String, Multiset<String>> facets) { JSONObject results = new JSONObject(); for (Entry<String, Multiset<String>> entry : facets.entrySet()) { JSONObject value = new JSONObject(); for (String catValue : entry.getValue()) { value.put(catValue, entry.getValue().count(catValue)); }/*from ww w. j a v a 2s . c om*/ results.put(entry.getKey(), value); } return results; }
From source file:io.github.theluca98.textapi.Title.java
static JSONObject convert(String text) { JSONObject json = new JSONObject(); json.put("text", text); return json;//w ww .j ava 2 s.c om }
From source file:net.amigocraft.mpt.command.UpdateCommand.java
@SuppressWarnings("unchecked") public static void updateStore() throws MPTException { if (Thread.currentThread().getId() == Main.mainThreadId) throw new MPTException(ERROR_COLOR + "Package store may not be updated from the main thread!"); lockStores();/*from w ww . j av a 2s . c o m*/ final File rStoreFile = new File(Main.plugin.getDataFolder(), "repositories.json"); if (!rStoreFile.exists()) Main.initializeRepoStore(rStoreFile); // gotta initialize it before using it final File pStoreFile = new File(Main.plugin.getDataFolder(), "packages.json"); if (!pStoreFile.exists()) Main.initializePackageStore(pStoreFile); JSONObject repos = (JSONObject) Main.repoStore.get("repositories"); Set<Map.Entry> entries = repos.entrySet(); JSONObject localPackages = (JSONObject) Main.packageStore.get("packages"); List<Object> remove = new ArrayList<Object>(); for (Object k : localPackages.keySet()) { if (!((JSONObject) localPackages.get(k)).containsKey("installed")) remove.add(k); } for (Object r : remove) localPackages.remove(r); for (Map.Entry<String, JSONObject> e : entries) { final String id = e.getKey().toLowerCase(); JSONObject repo = e.getValue(); final String url = repo.get("url").toString(); if (VERBOSE) Main.log.info("Updating repository \"" + id + "\""); JSONObject json = MiscUtil.getRemoteIndex(url); String repoId = json.get("id").toString(); JSONObject packages = (JSONObject) json.get("packages"); Set<Map.Entry> pEntries = packages.entrySet(); for (Map.Entry en : pEntries) { String packId = en.getKey().toString().toLowerCase(); JSONObject o = (JSONObject) en.getValue(); if (o.containsKey("name") && o.containsKey("version") && o.containsKey("url")) { if (o.containsKey("sha1") || !Config.ENFORCE_CHECKSUM) { String name = o.get("name").toString(); String desc = o.containsKey("description") ? o.get("description").toString() : ""; String version = o.get("version").toString(); String contentUrl = o.get("url").toString(); String sha1 = o.containsKey("sha1") ? o.get("sha1").toString() : ""; if (VERBOSE) Main.log.info("Fetching package \"" + packId + "\""); String installed = localPackages.containsKey(packId) && ((JSONObject) localPackages.get(packId)).containsKey("installed") ? (((JSONObject) localPackages.get(packId)).get("installed")).toString() : ""; JSONArray files = localPackages.containsKey(packId) && ((JSONObject) localPackages.get(packId)).containsKey("files") ? ((JSONArray) ((JSONObject) localPackages.get(packId)).get("files")) : null; JSONObject pObj = new JSONObject(); pObj.put("repo", repoId); pObj.put("name", name); if (!desc.isEmpty()) pObj.put("description", desc); pObj.put("version", version); pObj.put("url", contentUrl); if (!sha1.isEmpty()) pObj.put("sha1", sha1); if (!installed.isEmpty()) pObj.put("installed", installed); if (files != null) pObj.put("files", files); localPackages.put(packId, pObj); } else if (VERBOSE) Main.log.warning("Missing checksum for package \"" + packId + ".\" Ignoring package..."); } else if (VERBOSE) Main.log.warning( "Found invalid package definition \"" + packId + "\" in repository \"" + repoId + "\""); } } Main.packageStore.put("packages", localPackages); try { writePackageStore(); } catch (IOException ex) { throw new MPTException(ERROR_COLOR + "Failed to save repository store to disk!"); } unlockStores(); }
From source file:hoot.services.controllers.job.JobControllerBase.java
protected static JSONArray parseParams(String params) throws ParseException { JSONParser parser = new JSONParser(); JSONObject command = (JSONObject) parser.parse(params); JSONArray commandArgs = new JSONArray(); for (Object o : command.entrySet()) { Map.Entry<Object, Object> mEntry = (Map.Entry<Object, Object>) o; String key = (String) mEntry.getKey(); String val = (String) mEntry.getValue(); JSONObject arg = new JSONObject(); arg.put(key, val); commandArgs.add(arg);/*from w w w.j a va2 s.c o m*/ } return commandArgs; }
From source file:model.Post_store.java
public static void setlastid(int lastid) { JSONObject obj = new JSONObject(); obj.put("lastid", lastid); try (FileWriter file = new FileWriter(root + "posts/lastid.json");) { file.write(obj.toJSONString());// w w w. j a v a 2s. c om file.flush(); file.close(); } catch (IOException ex) { System.out.println(ex); } }
From source file:it.cnr.isti.thematrix.scripting.sys.DatasetSchema.java
/** * Converts the argument schema into a JSON String * @param schema/* ww w . j ava2s . c o m*/ * @return he argument schema into a JSON String */ public static String toJSON(DatasetSchema schema) { JSONArray list = new JSONArray(); list.add(schema.name); for (Symbol<?> s : schema.attributes()) { JSONObject obj = new JSONObject(); obj.put("name", s.name); obj.put("type", s.type.toString()); list.add(obj); } return list.toJSONString(); }
From source file:edu.usc.polar.CoreNLP.java
public static void StanfordCoreNLP(String doc, String args[]) { try {/*from w w w. j a v a2 s . c o m*/ String text; AutoDetectParser parser = new AutoDetectParser(); BodyContentHandler handler = new BodyContentHandler(); Metadata metadata = new Metadata(); if (args.length > 0) { serializedClassifier = args[0]; } if (args.length > 1) { String fileContents = IOUtils.slurpFile(args[1]); List<List<CoreLabel>> out = classifier.classify(fileContents); for (List<CoreLabel> sentence : out) { for (CoreLabel word : sentence) { System.out .print(word.word() + '/' + word.get(CoreAnnotations.AnswerAnnotation.class) + ' '); } System.out.println(); } out = classifier.classifyFile(args[1]); for (List<CoreLabel> sentence : out) { for (CoreLabel word : sentence) { System.out .print(word.word() + '/' + word.get(CoreAnnotations.AnswerAnnotation.class) + ' '); } System.out.println(); } } else { InputStream stream = new FileInputStream(doc); //ParsingExample.class.getResourceAsStream(doc) ; // System.out.println(stream.toString()); parser.parse(stream, handler, metadata); // return handler.toString(); text = handler.toString(); String metaValue = metadata.toString(); // System.out.println("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") .replace("\\", "."); List<Triple<String, Integer, Integer>> list = classifier.classifyToCharacterOffsets(text); JSONObject jsonObj = new JSONObject(); jsonObj.put("DOI", name); jsonObj.put("metadata", metaValue.replaceAll("\\s\\s+|\n|\t", " ")); JSONArray tempArray = new JSONArray(); JSONObject tempObj = new JSONObject(); for (Triple<String, Integer, Integer> item : list) { // String jsonOut="{ DOI:"+name+" ," // + ""+item.first() + "\": \"" + text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t"," ")+"\"" // + "\"metadata\":\""+metaValue+"\"" // + "}"; // System.out.println(jsonOut); tempObj.put(item.first(), text.substring(item.second(), item.third()).replaceAll("\\s\\s+|\n|\t", " ")); } tempArray.add(tempObj); jsonObj.put("NER", tempArray); jsonArray.add(jsonObj); } // System.out.println("---"); } catch (Exception e) { System.out.println("ERROR : CoreNLP" + "|File Name" + doc.replaceAll("C:\\Users\\Snehal\\Documents\\TREC-Data", "") + " direct" + e.toString()); } }
From source file:edu.iu.incntre.flowscale.util.JSONConverter.java
/** * convert from aggregate stats to JSONArray * //from ww w . j av a 2 s .com * @param ofs * @return JSONArray of aggregate stats */ public static JSONArray toAggregateStat(List<OFStatistics> ofs) { JSONArray jsonArray = new JSONArray(); for (OFStatistics ofst : ofs) { OFAggregateStatisticsReply st = (OFAggregateStatisticsReply) ofst; JSONObject jsonObject = new JSONObject(); jsonObject.put("packet_count", st.getPacketCount()); jsonObject.put("flow_count", st.getFlowCount()); jsonArray.add(jsonObject); } return jsonArray; }
From source file:edu.vt.vbi.patric.portlets.DiseaseOverview.java
@SuppressWarnings("unchecked") public static JSONObject encodeNodeJSONObject(ResultType rt) { JSONObject obj = new JSONObject(); obj.putAll(rt);// w ww.jav a2 s.c o m obj.put("id", rt.get("tree_node")); obj.put("node", rt.get("tree_node")); obj.put("expanded", "true"); if (rt.get("leaf").equals("1")) { obj.put("leaf", "true"); } else { obj.put("leaf", "false"); } return obj; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java
protected static void iniciarWSC(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<UsuarioEntity> usuarios = CtrlAdmin.iniciarWSC(Integer.parseInt(request.getParameter("1")), //id evento Integer.parseInt(request.getParameter("2")), //tamao tabla Integer.parseInt(request.getParameter("3"))//pagina ); // parameter 1: documentoDocente param2: idTaller response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONArray list1 = new JSONArray(); for (UsuarioEntity usuario : usuarios) { JSONObject obj = new JSONObject(); obj.put("id", usuario.getIdUsuario()); obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos()); list1.add(obj);/* ww w. j av a 2s . c o m*/ } out.print(list1); }