List of usage examples for org.json JSONArray getString
public String getString(int index) throws JSONException
From source file:net.portalblockz.portalbot.serverdata.JSONConfigManager.java
public void serializeBlacklist() { JSONArray blackList = configObject.optJSONArray("blacklist-words"); if (blackList != null) { for (int i = 0; i < blackList.length(); i++) { if (!blacklistWords.contains(blackList.getString(i).toLowerCase())) { blacklistWords.add(blackList.getString(i).toLowerCase()); }/*from w w w. j a v a 2 s.co m*/ } } }
From source file:com.watabou.pixeldungeon.utils.Bundle.java
public String[] getStringArray(String key) { try {/*w ww.j a v a2 s. c o m*/ JSONArray array = data.getJSONArray(key); int length = array.length(); String[] result = new String[length]; for (int i = 0; i < length; i++) { result[i] = array.getString(i); } return result; } catch (JSONException e) { return null; } }
From source file:ai.susi.mind.SusiSkill.java
/** * Create a skill by parsing of the skill description * @param json the skill description//from w ww . j a va 2 s . co m * @throws PatternSyntaxException */ private SusiSkill(JSONObject json) throws PatternSyntaxException { // extract the phrases and the phrases subscore if (!json.has("phrases")) throw new PatternSyntaxException("phrases missing", "", 0); JSONArray p = (JSONArray) json.remove("phrases"); this.phrases = new ArrayList<>(p.length()); p.forEach(q -> this.phrases.add(new SusiPhrase((JSONObject) q))); // extract the actions and the action subscore if (!json.has("actions")) throw new PatternSyntaxException("actions missing", "", 0); p = (JSONArray) json.remove("actions"); this.actions = new ArrayList<>(p.length()); p.forEach(q -> this.actions.add(new SusiAction((JSONObject) q))); // extract the inferences and the process subscore; there may be no inference at all if (json.has("process")) { p = (JSONArray) json.remove("process"); this.inferences = new ArrayList<>(p.length()); p.forEach(q -> this.inferences.add(new SusiInference((JSONObject) q))); } else { this.inferences = new ArrayList<>(0); } // extract (or compute) the keys; there may be none key given, then they will be computed this.keys = new HashSet<>(); JSONArray k; if (json.has("keys")) { k = json.getJSONArray("keys"); if (k.length() == 0 || (k.length() == 1 && k.getString(0).length() == 0)) k = computeKeysFromPhrases(this.phrases); } else { k = computeKeysFromPhrases(this.phrases); } k.forEach(o -> this.keys.add((String) o)); this.user_subscore = json.has("score") ? json.getInt("score") : DEFAULT_SCORE; this.score = null; // calculate this later if required // extract the comment this.comment = json.has("comment") ? json.getString("comment") : ""; // calculate the id String ids0 = this.actions.toString(); String ids1 = this.phrases.toString(); this.id = ids0.hashCode() + ids1.hashCode(); }
From source file:org.dasein.cloud.joyent.SmartDataCenter.java
public @Nonnull String getEndpoint() throws CloudException, InternalException { ProviderContext ctx = getContext();/*from w ww .j a va 2s .c om*/ if (ctx == null) { throw new CloudException("No context has been established for this request"); } String e = ctx.getEndpoint(); if (e == null) { e = "https://us-west-1.api.joyentcloud.com"; } String[] parts = e.split(","); if (parts == null || parts.length < 1) { parts = new String[] { e }; } String r = ctx.getRegionId(); if (r == null) { return parts[0]; } if (endpointCache.containsKey(e)) { Map<String, String> cache = endpointCache.get(e); if (cache != null && cache.containsKey(r)) { String endpoint = cache.get(r); if (endpoint != null) { return endpoint; } } } JoyentMethod method = new JoyentMethod(this); String json = method.doGetJson(parts[0], "datacenters"); try { JSONObject ob = new JSONObject(json); JSONArray ids = ob.names(); for (int i = 0; i < ids.length(); i++) { String regionId = ids.getString(i); if (regionId.equals(r) && ob.has(regionId)) { String endpoint = ob.getString(regionId); Map<String, String> cache; if (endpointCache.containsKey(e)) { cache = endpointCache.get(e); } else { cache = new HashMap<String, String>(); endpointCache.put(e, cache); } cache.put(r, endpoint); return endpoint; } } throw new CloudException("No endpoint exists for " + r); } catch (JSONException ex) { throw new CloudException(ex); } }
From source file:com.phonegap.Storage.java
/** * Executes the request and returns PluginResult. * //from w ww. ja va 2 s. c o m * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. */ public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try { // TODO: Do we want to allow a user to do this, since they could get to other app databases? if (action.equals("setStorage")) { this.setStorage(args.getString(0)); } else if (action.equals("openDatabase")) { this.openDatabase(args.getString(0), args.getString(1), args.getString(2), args.getLong(3)); } else if (action.equals("executeSql")) { JSONArray a = args.getJSONArray(1); int len = a.length(); String[] s = new String[len]; for (int i = 0; i < len; i++) { s[i] = a.getString(i); } this.executeSql(args.getString(0), s, args.getString(2)); } return new PluginResult(status, result); } catch (JSONException e) { return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }
From source file:com.liferay.mobile.android.v62.portal.PortalService.java
public String getAutoDeployDirectory() throws Exception { JSONObject _command = new JSONObject(); try {/*from www .j a va2 s .co m*/ JSONObject _params = new JSONObject(); _command.put("/portal/get-auto-deploy-directory", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getString(0); }
From source file:net.zionsoft.obadiah.model.translations.TranslationHelper.java
public static void saveBookNames(SQLiteDatabase db, JSONObject booksInfoObject) throws Exception { final String translationShortName = booksInfoObject.getString("shortName"); final ContentValues bookNamesValues = new ContentValues(3); bookNamesValues.put(DatabaseHelper.COLUMN_TRANSLATION_SHORT_NAME, translationShortName); final JSONArray booksArray = booksInfoObject.getJSONArray("books"); for (int i = 0; i < Bible.getBookCount(); ++i) { bookNamesValues.put(DatabaseHelper.COLUMN_BOOK_INDEX, i); final String bookName = booksArray.getString(i); if (TextUtils.isEmpty(bookName)) throw new Exception("Illegal books.json file: " + translationShortName); bookNamesValues.put(DatabaseHelper.COLUMN_BOOK_NAME, bookName); db.insert(DatabaseHelper.TABLE_BOOK_NAMES, null, bookNamesValues); }// w ww . j a v a 2 s. c om }
From source file:net.zionsoft.obadiah.model.translations.TranslationHelper.java
public static void saveVerses(SQLiteDatabase db, String translationShortName, int bookIndex, int chapterIndex, JSONObject versesObject) throws Exception { final ContentValues versesValues = new ContentValues(4); versesValues.put(DatabaseHelper.COLUMN_BOOK_INDEX, bookIndex); versesValues.put(DatabaseHelper.COLUMN_CHAPTER_INDEX, chapterIndex); final JSONArray paragraphArray = versesObject.getJSONArray("verses"); final int paragraphCount = paragraphArray.length(); boolean hasNonEmptyVerse = false; for (int verseIndex = 0; verseIndex < paragraphCount; ++verseIndex) { versesValues.put(DatabaseHelper.COLUMN_VERSE_INDEX, verseIndex); final String verse = paragraphArray.getString(verseIndex); if (!hasNonEmptyVerse && !TextUtils.isEmpty(verse)) hasNonEmptyVerse = true;/* ww w .j ava 2s . co m*/ versesValues.put(DatabaseHelper.COLUMN_TEXT, verse); db.insert(translationShortName, null, versesValues); } if (!hasNonEmptyVerse) { throw new Exception( String.format("Empty chapter: %s %d-%d", translationShortName, bookIndex, chapterIndex)); } }
From source file:com.tweetlanes.android.App.java
public void onPostSignIn(TwitterUser user, String oAuthToken, String oAuthSecret, SocialNetConstant.Type oSocialNetType) { if (user != null) { try {/*from ww w .j a va 2 s.c o m*/ final Editor edit = mPreferences.edit(); String userIdAsString = Long.toString(user.getId()); AccountDescriptor account = new AccountDescriptor(this, user, oAuthToken, oAuthSecret, oSocialNetType); edit.putString(getAccountDescriptorKey(user.getId()), account.toString()); String accountIndices = mPreferences.getString(SHARED_PREFERENCES_KEY_ACCOUNT_INDICES, null); JSONArray jsonArray; if (accountIndices == null) { jsonArray = new JSONArray(); jsonArray.put(0, user.getId()); mAccounts.add(account); } else { jsonArray = new JSONArray(accountIndices); boolean exists = false; for (int i = 0; i < jsonArray.length(); i++) { String c = jsonArray.getString(i); if (c.compareTo(userIdAsString) == 0) { exists = true; mAccounts.set(i, account); break; } } if (exists == false) { jsonArray.put(userIdAsString); mAccounts.add(account); } } accountIndices = jsonArray.toString(); edit.putString(SHARED_PREFERENCES_KEY_ACCOUNT_INDICES, accountIndices); edit.commit(); setCurrentAccount(user.getId()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } updateTwitterAccountCount(); if (TwitterManager.get().getSocialNetType() == oSocialNetType) { TwitterManager.get().setOAuthTokenWithSecret(oAuthToken, oAuthSecret, true); } else { TwitterManager.initModule(oSocialNetType, oSocialNetType == SocialNetConstant.Type.Twitter ? ConsumerKeyConstants.TWITTER_CONSUMER_KEY : ConsumerKeyConstants.APPDOTNET_CONSUMER_KEY, oSocialNetType == SocialNetConstant.Type.Twitter ? ConsumerKeyConstants.TWITTER_CONSUMER_SECRET : ConsumerKeyConstants.APPDOTNET_CONSUMER_SECRET, oAuthToken, oAuthSecret, getCurrentAccountKey(), mConnectionStatusCallbacks); } } }
From source file:de.dakror.virtualhub.data.Catalog.java
public Catalog(JSONObject o) { try {/* w ww . jav a 2 s. com*/ name = o.getString("name"); JSONArray sources = o.getJSONArray("sources"); for (int i = 0; i < sources.length(); i++) this.sources.add(new File(sources.getString(i))); JSONArray tags = o.getJSONArray("tags"); for (int i = 0; i < tags.length(); i++) this.tags.add(tags.getString(i)); } catch (JSONException e) { e.printStackTrace(); } }