List of usage examples for org.json JSONObject getJSONArray
public JSONArray getJSONArray(String key) throws JSONException
From source file:edu.stanford.junction.api.activity.ActivityScript.java
public void addRoleHint(String role, String hint) { try {//from w ww .j ava2 s. c o m if (roleSpecs == null) roleSpecs = new JSONObject(); if (!roleSpecs.has(role)) { roleSpecs.put(role, new JSONObject()); } JSONObject jsonRole = roleSpecs.getJSONObject(role); if (!jsonRole.has("hints")) { jsonRole.put("hints", new JSONArray()); } JSONArray jsonHints = jsonRole.getJSONArray("hints"); jsonHints.put(hint); mJSON = null; // reset } catch (Exception e) { e.printStackTrace(); } }
From source file:ca.canucksoftware.ipkpackager.IpkPackagerView.java
public void readFromControlFile(File control) { try {/*from w w w .ja v a2 s .c o m*/ BufferedReader input = new BufferedReader(new FileReader(control)); String line = input.readLine(); while (line != null) { line = line.trim(); if (line.length() > 0 && line.indexOf(":") != line.length() - 1) { if (line.startsWith("Package")) { jTextField5.setText(line.substring(line.indexOf(":") + 2)); } else if (line.startsWith("Description")) { jTextField3.setText(line.substring(line.indexOf(":") + 2)); } else if (line.startsWith("Version")) { jTextField6.setText( line.substring(line.indexOf(":") + 2).replaceAll("-", ".").replaceAll("_", ".")); } else if (line.startsWith("Architecture")) { setArch(line.substring(line.indexOf(":") + 2)); } else if (line.startsWith("Maintainer")) { jTextField7.setText(line.substring(line.indexOf(":") + 2)); } else if (line.startsWith("Depends")) { String[] tokens = line.substring(line.indexOf(":") + 2).split(","); for (int i = 0; i < tokens.length; i++) { tokens[i] = tokens[i].trim(); if (!depends.contains(tokens[i])) { depends.add(tokens[i]); } } jList2.setListData(depends.toArray()); } else if (line.startsWith("Source")) { JSONObject src = new JSONObject(line.substring(line.indexOf(":") + 2)); if (src.has("Icon")) { jTextField4.setText(src.getString("Icon")); } if (src.has("Screenshots")) { JSONArray ss = src.getJSONArray("Screenshots"); for (int i = 0; i < ss.length(); i++) { if (!ssURLs.contains(ss.getString(i))) { ssURLs.add(ss.getString(i)); } } jList1.setListData(ssURLs.toArray()); } if (src.has("FullDescription")) { jTextArea2.setText(src.getString("FullDescription").replaceAll("<br>", "\n")); } if (src.has("Homepage")) { jTextField9.setText(src.getString("Homepage")); } if (src.has("Type")) { setType(src.getString("Type")); } if (src.has("Category")) { jTextField12.setText(src.getString("Category")); } if (src.has("License")) { jTextField11.setText(src.getString("License")); } if (src.has("Location")) { jTextField10.setText(src.getString("Location")); } if (src.has("PostInstallFlags")) { setFlag(jComboBox2, src.getString("PostInstallFlags")); } if (src.has("PostUpdateFlags")) { setFlag(jComboBox3, src.getString("PostUpdateFlags")); } if (src.has("PostRemoveFlags")) { setFlag(jComboBox4, src.getString("PostRemoveFlags")); } } } line = input.readLine(); } } catch (Exception e) { } }
From source file:com.kupriyanov.android.apps.translate.service.WorkerThread.java
/** * Read and return the content for a specific Wiktionary page. This makes a * lightweight API call, and trims out just the page content returned. * Because this call blocks until results are available, it should not be run * from a UI thread.// w w w . j av a 2 s .c o m * * @param title * The exact title of the Wiktionary page requested. * @param expandTemplates * If true, expand any wiki templates found. * @return Exact content of page. * @throws ApiException * If any connection or server error occurs. * @throws ParseException * If there are problems parsing the response. */ public static String getPageContent2(String apiQuery, boolean expandTemplates) throws ApiException, ParseException { String content = getUrlContent(apiQuery); Log.d(TAG, "[RESPONSE->]:" + content); try { // Drill into the JSON response to find the content body JSONObject response = new JSONObject(content); JSONObject data = response.getJSONObject("data"); // JSONObject pages = data.getJSONObject("translations"); // JSONObject page = pages.getJSONObject((String) pages.keys().next()); JSONArray translations = data.getJSONArray("translations"); JSONObject revision = translations.getJSONObject(0); return revision.getString("translatedText"); } catch (JSONException e) { throw new ParseException("Problem parsing API response:" + content, e); } }
From source file:com.kupriyanov.android.apps.translate.service.WorkerThread.java
public static String detectLanguage(String apiQuery) throws ApiException, ParseException { String content = getUrlContent(apiQuery); Log.d(TAG, "[RESPONSE->]:" + content); try {//from w ww . j a v a 2 s . com // Drill into the JSON response to find the content body final JSONObject response = new JSONObject(content); final JSONObject data = response.getJSONObject("data"); final JSONArray detections = data.getJSONArray("detections"); final JSONArray detectionArr = detections.getJSONArray(0); final JSONObject detectionObj = detectionArr.getJSONObject(0); // language": "de", // "isReliable": false, // "confidence": 1.0 return detectionObj.getString("language"); } catch (JSONException e) { throw new ParseException("Problem parsing API response:" + content, e); } }
From source file:com.domuslink.api.DomusHandler.java
public String[] getFloorPlan() throws Exception { JSONArray theList = null;//from www. ja v a 2 s. c o m JSONObject theResponse = null; String[] theFloorPlan; if (this.hostPath != null || this.hostPath.length() != 0) { ApiHandler.prepareUserAgent(this.c, authPass, hostPath); try { if (this.visible) theResponse = ApiHandler.getPageContent(this, "floorplan", "true"); else theResponse = ApiHandler.getPageContent(this, "floorplan", "false"); } catch (Exception e) { Log.e(TAG, "Error getting floorplan page content at " + this.hostPath, e); throw e; } try { theList = theResponse.getJSONArray("floorplan"); } catch (Exception e) { Log.e(TAG, "Error getting floorplan from JSONObject", e); throw e; } theFloorPlan = new String[theList.length()]; for (int i = 0; i < theList.length(); i++) { try { theFloorPlan[i] = theList.getString(i); } catch (Exception e) { Log.e(TAG, "Error getting floorplan from JSONArray", e); throw e; } } } else theFloorPlan = EMPTY_LIST; return theFloorPlan; }
From source file:com.domuslink.api.DomusHandler.java
public Alias[] getAliasesByLocation(String theLocation) throws Exception { JSONArray theList = null;//from w ww . j a v a2s . co m JSONObject theResponse = null; Alias[] theAliases; // Log.i(TAG, "Entering DomusHandler.getAliasesByLocation: "+theLocation); if (this.hostPath != null || this.hostPath.length() != 0) { ApiHandler.prepareUserAgent(this.c, authPass, hostPath); try { if (this.visible) { if (this.theVersion.getDomusApiVersion() < 5) theResponse = ApiHandler.getPageContent(this, "location", theLocation + "/true"); else theResponse = ApiHandler.getPageContent(this, "location", theLocation + "/true/true"); } else { if (this.theVersion.getDomusApiVersion() < 5) theResponse = ApiHandler.getPageContent(this, "location", theLocation + "/false"); else theResponse = ApiHandler.getPageContent(this, "location", theLocation + "/false/true"); } } catch (Exception e) { Log.e(TAG, "Error getting aliases by location page content at " + this.hostPath, e); throw e; } try { theList = theResponse.getJSONArray(theLocation); } catch (Exception e) { Log.e(TAG, "Error getting aliases by location from JSONObject", e); throw e; } theAliases = new Alias[theList.length()]; for (int i = 0; i < theList.length(); i++) { try { theAliases[i] = new Alias(theList.getJSONObject(i)); getAliasState(theAliases[i]); } catch (Exception e) { Log.e(TAG, "Error getting aliases by location from JSONArray", e); throw e; } } } else theAliases = null; // Log.d(TAG, "At DomusHandler.getAliasesByLocation return, Alias list length is "+theAliases.length); return theAliases; }
From source file:com.domuslink.api.DomusHandler.java
public Module[] getModuleTypes() throws Exception { JSONArray theList = null;/*from w ww .j a va 2s . co m*/ JSONObject theResponse = null; Module[] theModules; // Log.i(TAG, "Entering DomusHandler.getAliasesByLocation: "+theLocation); if (this.hostPath != null || this.hostPath.length() != 0) { ApiHandler.prepareUserAgent(this.c, authPass, hostPath); try { if (this.visible) theResponse = ApiHandler.getPageContent(this, "moduletypes", null); else theResponse = ApiHandler.getPageContent(this, "moduletypes", null); } catch (Exception e) { Log.e(TAG, "Error getting module types page content at " + this.hostPath, e); throw e; } try { theList = theResponse.getJSONArray("moduletypes"); } catch (Exception e) { Log.e(TAG, "Error getting module types from JSONObject", e); throw e; } theModules = new Module[theList.length()]; for (int i = 0; i < theList.length(); i++) { try { theModules[i] = new Module(theList.getJSONObject(i)); } catch (Exception e) { Log.e(TAG, "Error getting module types from JSONArray", e); throw e; } } } else theModules = null; // Log.d(TAG, "At DomusHandler.getAModuleTypes return, Module list length is "+theModules.length); return theModules; }
From source file:com.ProfessorPopTart.alternateouyastore.MainActivity.java
/** * This is used to fill gameList with data from the JSON apps object * <p>/*w ww . j a v a2 s.c o m*/ * The object is then used as a dataset for the ListView that shows the game titles * * @param gameList an ArrayList of strings */ public void fillList(ArrayList<String> gameList) { try { JSONObject MyResults = new JSONObject(HttpResults); for (int i = 0; i < MyResults.getJSONArray("apps").length(); i++) { String title = MyResults.getJSONArray("apps").getJSONObject(i).getString("title"); gameList.add(i, title); } } catch (Exception e) { e.printStackTrace(); } GameListAdapter.notifyDataSetChanged(); }
From source file:com.ProfessorPopTart.alternateouyastore.MainActivity.java
/** * This will get the img url of a game from the JSON apps response * * @param title String title of the game. * @returns the imgUrl as a string.//w w w. j av a2 s . co m */ private String getImgUrl(String title) { String url = "x"; try { JSONObject MyResults = new JSONObject(HttpResults); for (int i = 0; i < MyResults.getJSONArray("apps").length(); i++) { String searchTitle = MyResults.getJSONArray("apps").getJSONObject(i).getString("title"); String searchUrl = MyResults.getJSONArray("apps").getJSONObject(i).getString("mainImageFullUrl"); if (searchTitle.equals(title)) { url = searchUrl; } } } catch (Exception e) { e.printStackTrace(); } GameListAdapter.notifyDataSetChanged(); return url; }
From source file:com.ProfessorPopTart.alternateouyastore.MainActivity.java
/** * This will get the "version" (uid) of a game from the JSON apps response * * @param title String title of the game. * @returns the version as a string.//from w w w . ja v a2s. c o m */ private String getUuid(String title) { String version = "x"; try { JSONObject MyResults = new JSONObject(HttpResults); for (int i = 0; i < MyResults.getJSONArray("apps").length(); i++) { String searchTitle = MyResults.getJSONArray("apps").getJSONObject(i).getString("title"); String searchVersion = MyResults.getJSONArray("apps").getJSONObject(i).getString("version"); if (searchTitle.equals(title)) { version = searchVersion; } } } catch (Exception e) { e.printStackTrace(); } GameListAdapter.notifyDataSetChanged(); return version; }