List of usage examples for org.json.simple JSONObject keySet
Set<K> keySet();
From source file:me.timothy.ddd.entities.EntityInfo.java
@Override public void loadFrom(JSONObject jsonObject) { Set<?> keys = jsonObject.keySet(); for (Object o : keys) { if (!(o instanceof String)) continue; String key = (String) o; switch (key.toLowerCase()) { case "health": health = getInt(jsonObject, key); break; case "image": image = getString(jsonObject, key); break; case "meta": meta.loadFrom(getObject(jsonObject, key)); break; case "position": position.loadFrom(getObject(jsonObject, key)); break; case "conversation": conversation.loadFrom(getObject(jsonObject, key)); break; case "inventory": inventory.loadFrom(getObject(jsonObject, key)); break; case "inventory_lost": inventoryLost.loadFrom(getObject(jsonObject, key)); break; default://from ww w . j a v a2s .co m EntityConversationInfo eci = new EntityConversationInfo(); eci.loadFrom(getObject(jsonObject, key)); potentialConversations.put(key, eci); break; } } }
From source file:it.polimi.diceH2020.plugin.control.JSonReader.java
public void createMap(String jsonFilePath) { FileReader reader;/*from ww w . j ava 2s. c om*/ try { reader = new FileReader(jsonFilePath); JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject) jsonParser.parse(reader); Set<?> keys = jsonObject.keySet(); for (Object s : keys) { this.idClassUmlFile.put((String) s, (String) jsonObject.get(s)); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:io.fabric8.mq.controller.coordination.KubernetesControl.java
private ObjectName getBrokerJMXRoot(J4pClient client) throws Exception { String type = "org.apache.activemq:*,type=Broker"; String attribute = "BrokerName"; ObjectName objectName = new ObjectName(type); J4pResponse<J4pReadRequest> result = client.execute(new J4pReadRequest(objectName, attribute)); JSONObject jsonObject = result.getValue(); return new ObjectName(jsonObject.keySet().iterator().next().toString()); }
From source file:gwap.game.quiz.PlayNHighscoreCommunicationResource.java
private QuizHighscore readOutJSONData(HttpServletRequest request) throws IOException { QuizHighscore quizHighscore = null;/*from www. j a v a2 s .c o m*/ BufferedReader reader = request.getReader(); StringBuilder sb = new StringBuilder(); String line = reader.readLine(); while (line != null) { sb.append(line + "\n"); line = reader.readLine(); } reader.close(); String data = sb.toString(); if (data.equals("")) { return null; } JSONParser parser = new JSONParser(); quizHighscore = new QuizHighscore(); quizHighscore.setCreated(new Date()); Object obj; try { obj = parser.parse(data); JSONObject jsonObject = (JSONObject) obj; for (Object k : jsonObject.keySet()) { Object value = jsonObject.get(k); String key = (String) k; if (key.equals("Name")) { quizHighscore.setUsername((String) value); } else if (key.equals("PunkteAnzahl")) { quizHighscore.setScore(((Long) value).intValue()); } else if (key.equals("Joker")) { quizHighscore.setJoker(((Long) value).intValue()); } else if (key.equals("Frage")) { quizHighscore.setQuestion(((Long) value).intValue()); } else if (key.equals("Action")) { this.action = (String) value; } else if (key.equals("HighScoreMode")) { this.mode = (String) value; } } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return quizHighscore; }
From source file:eu.edisonproject.training.wsd.WikipediaOnline.java
private Set<Term> queryTerms(String jsonString, String originalTerm) throws ParseException, IOException, MalformedURLException, InterruptedException, ExecutionException { Set<Term> terms = new HashSet<>(); Set<Term> termsToReturn = new HashSet<>(); JSONObject jsonObj = (JSONObject) JSONValue.parseWithException(jsonString); JSONObject query = (JSONObject) jsonObj.get("query"); JSONObject pages = (JSONObject) query.get("pages"); Set<String> keys = pages.keySet(); for (String key : keys) { JSONObject jsonpage = (JSONObject) pages.get(key); Term t = TermFactory.create(jsonpage, originalTerm); if (t != null) { terms.add(t);// w w w . ja va 2 s. c o m } } if (terms.size() > 0) { Map<CharSequence, List<CharSequence>> cats = getCategories(terms); for (Term t : terms) { boolean add = true; List<CharSequence> cat = cats.get(t.getUid()); t.setCategories(cat); for (CharSequence g : t.getGlosses()) { if (g != null && g.toString().contains("may refer to:")) { Set<Term> referToTerms = getReferToTerms(g.toString(), originalTerm); if (referToTerms != null) { for (Term rt : referToTerms) { String url = "https://en.wikipedia.org/?curid=" + rt.getUid(); rt.setUrl(url); termsToReturn.add(rt); } } add = false; break; } } if (add) { String url = "https://en.wikipedia.org/?curid=" + t.getUid(); t.setUrl(url); termsToReturn.add(t); } } } return termsToReturn; }
From source file:net.bashtech.geobot.JSONUtil.java
public static List<String> getEmotes() { List<String> emotes = new LinkedList<String>(); try {//from w ww. j a v a 2 s. com JSONParser parser = new JSONParser(); Object obj = parser.parse(BotManager.getRemoteContent("http://direct.twitchemotes.com/global.json")); JSONObject jsonObject = (JSONObject) obj; for (Object o : jsonObject.keySet()) { String name = (String) o; if (name.length() > 0) emotes.add(name); } Object obj1 = parser.parse(BotManager.getRemoteContent("https://api.betterttv.net/emotes")); JSONObject jsonObject1 = (JSONObject) obj1; JSONArray emotesObj = (JSONArray) jsonObject1.get("emotes"); for (int i = 0; i < emotesObj.size(); i++) { JSONObject emoteObject = (JSONObject) emotesObj.get(i); String emoteStr = (String) emoteObject.get("regex"); emotes.add(emoteStr); } emotes.add(":)"); emotes.add(":o"); emotes.add(":("); emotes.add(";)"); emotes.add(":/"); emotes.add(";p"); emotes.add(">("); emotes.add("B)"); emotes.add("O_o"); emotes.add("O_O"); emotes.add("R)"); emotes.add(":D"); emotes.add(":z"); emotes.add("D:"); emotes.add(":p"); emotes.add(":P"); } catch (Exception ex) { ex.printStackTrace(); } finally { return emotes; } }
From source file:io.fabric8.mq.controller.coordination.KubernetesControl.java
private BrokerOverview populateDestinations(J4pClient client, ObjectName root, BrokerDestinationOverviewImpl.Type type, BrokerOverview brokerOverview) { try {/*w ww . j a va 2 s .com*/ Hashtable<String, String> props = root.getKeyPropertyList(); props.put("destinationType", type == BrokerDestinationOverviewImpl.Type.QUEUE ? "Queue" : "Topic"); props.put("destinationName", "*"); String objectName = root.getDomain() + ":" + Utils.getOrderedProperties(props); J4pResponse<J4pReadRequest> response = client .execute(new J4pReadRequest(objectName, "Name", "QueueSize", "ConsumerCount", "ProducerCount")); JSONObject value = response.getValue(); for (Object key : value.keySet()) { //get the destinations JSONObject jsonObject = (JSONObject) value.get(key); String name = jsonObject.get("Name").toString(); String producerCount = jsonObject.get("ProducerCount").toString().trim(); String consumerCount = jsonObject.get("ConsumerCount").toString().trim(); String queueSize = jsonObject.get("QueueSize").toString().trim(); if (!name.contains("Advisory") && !name.contains(ActiveMQDestination.TEMP_DESTINATION_NAME_PREFIX)) { ActiveMQDestination destination = type == BrokerDestinationOverviewImpl.Type.QUEUE ? new ActiveMQQueue(name) : new ActiveMQTopic(name); BrokerDestinationOverviewImpl brokerDestinationOverviewImpl = new BrokerDestinationOverviewImpl( destination); brokerDestinationOverviewImpl.setNumberOfConsumers(Integer.parseInt(consumerCount)); brokerDestinationOverviewImpl.setNumberOfProducers(Integer.parseInt(producerCount)); brokerDestinationOverviewImpl.setQueueDepth(Integer.parseInt(queueSize)); brokerOverview.addDestinationStatistics(brokerDestinationOverviewImpl); } } } catch (Exception ex) { // Destinations don't exist yet on the broker LOG.debug("populateDestinations failed", ex); } return brokerOverview; }
From source file:com.dishant.iot.smarthome.stats.poller.mqtt.MqttPoller.java
@Override public void onMessageArrived(String topic, byte[] payload, int qos, boolean retained) { // Check if the get request was rejected if (!topic.startsWith(m_subTopicPrefix) && topic.endsWith("/get/rejected")) { // log the error only try {/*from ww w . j av a 2s . c om*/ JSONObject obj = (JSONObject) m_jsonParser.parse(new String(payload)); String code = (String) obj.get("code"); String message = (String) obj.get("message"); String timestamp = (String) obj.get("timestamp"); String clientToken = (String) obj.get("clientToken"); s_logger.warn("AWS IoT thing get rejected - code: {} message: {} timestamp: {} clientToken: {}", new Object[] { code, message, timestamp, clientToken }); } catch (ParseException e) { s_logger.error("Error while parsing AWS IoT thing get rejected message for topic: " + topic, e); } } // // Parse the message a create a metric object // See link // http://docs.aws.amazon.com/iot/latest/developerguide/thing-shadow-document-syntax.html#thing-shadow-example-response-json // for more details on the format of the response message try { JSONObject obj = (JSONObject) m_jsonParser.parse(new String(payload)); JSONObject stateObj = (JSONObject) obj.get("state"); JSONObject reportedObj = (JSONObject) stateObj.get("reported"); Iterator<?> iter = reportedObj.keySet().iterator(); while (iter.hasNext()) { String key = (String) iter.next(); Metric metric = new Metric(); metric.setMeasurement(key); metric.setValue(reportedObj.get(key)); // Get the thing name from the topic String thingName = topic.substring(m_subTopicPrefix.length(), topic.lastIndexOf("/shadow/get/accepted")); metric.setThingName(thingName); metric.setTimestamp(System.currentTimeMillis()); s_logger.debug("Received metric: " + metric.toString()); // Notify listener notifyListener(metric); } } catch (ParseException e) { s_logger.error("Error while parsing AWS IoT thing get accepted message for topic: " + topic, e); } }
From source file:com.des.paperbase.ManageData.java
public List<Map<String, Object>> select(String Tablename, Map<String, Object> value, String FilterType) throws ParseException { String data = g.readFileToString(PATH_FILE + "\\" + Tablename + ".json"); System.out.println(PATH_FILE + "\\" + Tablename + ".json"); JSONArray output = new JSONArray(); JSONObject json = (JSONObject) new JSONParser().parse(data); List<Map<String, Object>> result = new LinkedList<Map<String, Object>>(); GenerateFile g = new GenerateFile(); if (!data.equalsIgnoreCase("{\"data\":[]}")) { JSONArray OldValue = (JSONArray) json.get("data"); for (int s = 0; s < OldValue.size(); s++) { JSONObject record = (JSONObject) OldValue.get(s); if (MappingRecordAndKey(value, record, FilterType)) { List<String> Listkey = g.getKeyFromJSONArray(record.keySet()); Map<String, Object> Maprecord = new HashMap<String, Object>(); for (int i = 0; i < Listkey.size(); i++) { System.out.println(Listkey.get(i) + "," + record.get(Listkey.get(i))); Maprecord.put(Listkey.get(i), record.get(Listkey.get(i))); }/* w w w . jav a2s. c o m*/ result.add(Maprecord); } } } else { } return result; }
From source file:com.turt2live.uuid.turt2live.v1.ApiV1Service.java
@Override public List<PlayerRecord> doBulkLookup(UUID... uuids) { String list = combine(uuids); String response = doUrlRequest(getConnectionUrl() + "/name/list/" + list); if (response != null) { JSONObject json = (JSONObject) JSONValue.parse(response); if (json.containsKey("results")) { JSONObject object = (JSONObject) json.get("results"); List<PlayerRecord> records = new ArrayList<>(); for (Object key : object.keySet()) { UUID uuid = convertUuid(key.toString()); String name = (String) ((JSONObject) object.get(key)).get("name"); if (uuid == null || name.equals("unknown")) continue; PlayerRecord record = new Turt2LivePlayerRecord(uuid, name); records.add(record);// w w w .j av a2 s . co m } return records; } } return null; }