List of usage examples for org.json.simple JSONArray get
public E get(int index)
From source file:functionaltests.RestSchedulerJobPaginationTest.java
private void checkRevisionJobsInfo(String url, String... expectedIds) throws Exception { Set<String> expected = new HashSet<>(Arrays.asList(expectedIds)); Set<String> actual = new HashSet<>(); JSONObject page = getRequestJSONObject(url); JSONObject map = (JSONObject) page.get("map"); Assert.assertEquals(1, map.keySet().size()); JSONArray jobs = (JSONArray) map.get(map.keySet().iterator().next()); for (int i = 0; i < jobs.size(); i++) { JSONObject job = (JSONObject) jobs.get(i); actual.add((String) job.get("jobid")); }/*from ww w . j a va 2 s . c om*/ Assert.assertEquals("Unexpected result of 'revisionjobsinfo' request (" + url + ")", expected, actual); }
From source file:functionaltests.RestSchedulerJobTaskTest.java
@Test public void testGetJobTaskIds() throws Exception { String jobId = submitDefaultJob().value(); String resource = "jobs/" + jobId + "/tasks"; String schedulerUrl = getResourceUrl(resource); HttpGet httpGet = new HttpGet(schedulerUrl); setSessionHeader(httpGet);//ww w . j ava 2 s. c o m HttpResponse response = executeUriRequest(httpGet); assertHttpStatusOK(response); JSONObject jsonObject = toJsonObject(response); JSONArray jsonArray = (JSONArray) jsonObject.get("list"); assertEquals(getDefaultTaskName(), jsonArray.get(0).toString()); }
From source file:importer.handler.post.annotate.HTMLConverter.java
/** * Convert an xml->html converter with limited functionality * @param config the config specifying how to convert the tags+attributes *///from w w w. ja v a 2s. co m HTMLConverter(JSONArray config) { this.body = new StringBuilder(); this.patterns = config; map = new HashMap<Element, HTMLPattern>(); this.stack = new Stack<HTMLPattern>(); this.ignore = new HashSet<String>(); for (int i = 0; i < config.size(); i++) { JSONObject jObj = (JSONObject) config.get(i); String htmlTag = (String) jObj.get("htmlTag"); String xmlTag = (String) jObj.get("xmlTag"); String htmlAttrName = (String) jObj.get("htmlAttrName"); String htmlAttrValue = (String) jObj.get("htmlAttrValue"); String xmlAttrName = (String) jObj.get("xmlAttrName"); String xmlAttrValue = (String) jObj.get("xmlAttrValue"); addPattern(xmlTag, htmlTag, htmlAttrName, htmlAttrValue, xmlAttrName, xmlAttrValue); } }
From source file:interfaceTisseoWS.ST3.java
/** * Indique si l'une des lignes qui passe par cet arrt (format JSon) est une ligne au dpart de l'universit * @param dest/* w w w . java 2 s. c o m*/ * @return */ public boolean estDeservieDepuisPS(JSONArray dest) { String line; for (int i = 0; i < dest.size(); i++) { for (int j = 0; j < ((JSONArray) ((JSONObject) dest.get(i)).get("line")).size(); j++) { line = (String) ((JSONObject) ((JSONArray) ((JSONObject) dest.get(i)).get("line")).get(j)) .get("shortName"); if (estLignePS(line)) { lblResultat.setText("Votre zone est dsservie directement depuis \nPaul Sabatier par la ligne " + line + ", utilisez le rseau Tisso"); return true; } } } return false; }
From source file:net.bashtech.geobot.JSONUtil.java
public static ArrayList<String> BOIItems(String channel) { try {//from w w w . ja va 2 s . c o m JSONParser parser = new JSONParser(); Object obj = parser.parse( BotManager.getRemoteContent("http://coebot.tv/configs/boir/" + channel.substring(1) + ".json")); JSONObject jsonObject = (JSONObject) obj; JSONArray items = (JSONArray) jsonObject.get("items"); ArrayList<String> itemList = new ArrayList<String>(); for (int i = 0; i < items.size(); i++) { itemList.add((String) items.get(i)); } return itemList; } catch (Exception ex) { return null; } }
From source file:net.bashtech.geobot.JSONUtil.java
public static ArrayList<String> BOIFlyItems(String channel) { try {//from w w w .j a va2s . c o m JSONParser parser = new JSONParser(); Object obj = parser.parse( BotManager.getRemoteContent("http://coebot.tv/configs/boir/" + channel.substring(1) + ".json")); JSONObject jsonObject = (JSONObject) obj; JSONArray items = (JSONArray) jsonObject.get("flyItems"); ArrayList<String> itemList = new ArrayList<String>(); for (int i = 0; i < items.size(); i++) { itemList.add((String) items.get(i)); } return itemList; } catch (Exception ex) { return null; } }
From source file:matrix.CreateTextMatrix.java
public void textMatrix() throws UnsupportedEncodingException, FileNotFoundException, IOException, ParseException { CosSim cossim = new CosSim(); JSONParser jParser = new JSONParser(); BufferedReader in = new BufferedReader(new InputStreamReader( new FileInputStream("/Users/nSabri/Desktop/tweetMatris/userTweets.json"), "ISO-8859-9")); JSONArray a = (JSONArray) jParser.parse(in); File fout = new File("/Users/nSabri/Desktop/tweetMatris.csv"); FileOutputStream fos = new FileOutputStream(fout); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); for (int i = 0; i < 1000; i++) { for (int j = 0; j < 1000; j++) { JSONObject tweet1 = (JSONObject) a.get(i); JSONObject tweet2 = (JSONObject) a.get(j); String tweetText1 = tweet1.get("tweets").toString(); String tweetText2 = tweet2.get("tweets").toString(); double CosSimValue = cossim.Cosine_Similarity_Score(tweetText1, tweetText2); CosSimValue = Double.parseDouble(new DecimalFormat("##.###").format(CosSimValue)); bw.write(Double.toString(CosSimValue) + ", "); }//from w w w. ja v a 2 s .c o m bw.newLine(); } bw.close(); }
From source file:com.fujitsu.dc.test.jersey.ODataCommon.java
/** * Json??results?./*w w w . jav a2s .c o m*/ * @param json JSONObject * @param locationHeader LOCATION * @param type ? * @param additional ??? * @param np NP??? * @param etag etag??? * @param published published??? */ @SuppressWarnings("unchecked") public static final void checkResults(final JSONObject json, final String locationHeader, final String type, final Map<String, Object> additional, Map<String, String> np, String etag, String published) { String value; // d:__published????????? value = (String) json.get("__published"); assertNotNull(value); assertTrue(validDate(value)); // d:__published?????????? if (published != null) { assertEquals(published, value); } // d:__updated????????? value = (String) json.get("__updated"); assertNotNull(value); assertTrue(validDate(value)); // __metadata? JSONObject metadata = (JSONObject) json.get("__metadata"); // uri? value = (String) metadata.get("uri"); assertNotNull(value); if (locationHeader != null) { // LOCATION????? assertEquals(locationHeader, value); } // etag? value = (String) metadata.get("etag"); if (etag != null) { assertEquals(etag, value); } // type? value = (String) metadata.get("type"); assertNotNull(value); assertEquals(type, value); if (additional != null) { // ?? for (Map.Entry<String, Object> e : additional.entrySet()) { Object jsonValue = json.get(e.getKey()); if (jsonValue instanceof Integer) { jsonValue = ((Integer) jsonValue).longValue(); } if (jsonValue instanceof JSONArray) { JSONArray array = ((JSONArray) jsonValue); for (int i = 0; i < array.size(); i++) { if (array.get(i) instanceof Integer) { array.set(i, ((Integer) array.get(i)).longValue()); } } } Object expected = e.getValue(); if (expected instanceof Integer) { expected = ((Integer) expected).longValue(); } if (expected instanceof JSONArray) { JSONArray array = ((JSONArray) expected); for (int i = 0; i < array.size(); i++) { if (array.get(i) instanceof Integer) { array.set(i, ((Integer) array.get(i)).longValue()); } } } assertEquals(expected, jsonValue); } } if (np != null) { // NP??? for (Map.Entry<String, String> e : np.entrySet()) { JSONObject jsonValue = (JSONObject) json.get(e.getKey()); JSONObject defferedValue = (JSONObject) jsonValue.get("__deferred"); String uriValue = (String) defferedValue.get("uri"); assertEquals(e.getValue(), uriValue); } } }
From source file:net.bashtech.geobot.JSONUtil.java
public static ArrayList<String> BOIGuppyItems(String channel) { try {/*from www . jav a 2s. c om*/ JSONParser parser = new JSONParser(); Object obj = parser.parse( BotManager.getRemoteContent("http://coebot.tv/configs/boir/" + channel.substring(1) + ".json")); JSONObject jsonObject = (JSONObject) obj; JSONArray items = (JSONArray) jsonObject.get("guppyItems"); ArrayList<String> itemList = new ArrayList<String>(); for (int i = 0; i < items.size(); i++) { itemList.add((String) items.get(i)); } return itemList; } catch (Exception ex) { return null; } }
From source file:com.crazytest.config.TestCase.java
protected void login(String userName, String userPass) throws Exception { String endpoint = "/your-api/v2/login/"; String params = String.format("?username=%s&password=%s", userName, userPass); createHttpClient();/*www .ja va 2s.com*/ get(endpoint, params); HttpResponse httpResponse = getResponseOfGetRequest(); String httpResponseStringJsonString = EntityUtils.toString(httpResponse.getEntity()); LOGGER.info("Http response={}", httpResponseStringJsonString); JSONParser parser = new JSONParser(); Object obj = parser.parse(httpResponseStringJsonString); JSONObject jsonObject = (JSONObject) obj; Object userID = jsonObject.get("objectID"); Object authToken = jsonObject.get("authToken"); JSONArray classes = (JSONArray) jsonObject.get("classes"); JSONObject class1 = (JSONObject) classes.get(0); LOGGER.info("userID={}", userID.toString()); LOGGER.info("authToken={}", authToken.toString()); LOGGER.info("classID={}", class1.get("id")); this.userID = userID.toString(); this.authToken = authToken.toString(); this.classID = class1.get("id").toString(); }