List of usage examples for org.json JSONArray getJSONArray
public JSONArray getJSONArray(int index) throws JSONException
From source file:com.liferay.mobile.android.v62.assetcategory.AssetCategoryService.java
public JSONArray search(long groupId, String name, JSONArray categoryProperties, int start, int end) throws Exception { JSONObject _command = new JSONObject(); try {// w ww .j a v a 2 s .com JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("name", checkNull(name)); _params.put("categoryProperties", checkNull(categoryProperties)); _params.put("start", start); _params.put("end", end); _command.put("/assetcategory/search", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONArray(0); }
From source file:com.liferay.mobile.android.v62.assetcategory.AssetCategoryService.java
public JSONArray search(JSONArray groupIds, String name, JSONArray vocabularyIds, int start, int end) throws Exception { JSONObject _command = new JSONObject(); try {/*from www.j a va2s. c o m*/ JSONObject _params = new JSONObject(); _params.put("groupIds", checkNull(groupIds)); _params.put("name", checkNull(name)); _params.put("vocabularyIds", checkNull(vocabularyIds)); _params.put("start", start); _params.put("end", end); _command.put("/assetcategory/search", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONArray(0); }
From source file:com.liferay.mobile.android.v62.assetcategory.AssetCategoryService.java
public JSONArray search(long groupId, String keywords, long vocabularyId, int start, int end, JSONObjectWrapper obc) throws Exception { JSONObject _command = new JSONObject(); try {//from w w w . jav a2s. c o m JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("keywords", checkNull(keywords)); _params.put("vocabularyId", vocabularyId); _params.put("start", start); _params.put("end", end); mangleWrapper(_params, "obc", "com.liferay.portal.kernel.util.OrderByComparator", obc); _command.put("/assetcategory/search", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONArray(0); }
From source file:com.dubsar_dictionary.Dubsar.model.Sense.java
@Override public void parseData(Object jsonResponse) throws JSONException { JSONArray response = (JSONArray) jsonResponse; JSONArray _word = response.getJSONArray(1); JSONArray _synset = response.getJSONArray(2); int wordId = _word.getInt(0); String wordName = _word.getString(1); String wordPos = _word.getString(2); int synsetId = _synset.getInt(0); mGloss = new String(_synset.getString(1)); setPos(wordPos);// w w w. j a v a2s. c o m mWord = new Word(wordId, wordName, getPartOfSpeech()); mName = new String(wordName); mSynset = new Synset(synsetId, mGloss, getPartOfSpeech()); mIsWeakWordReference = mIsWeakSynsetReference = false; mWordReference = null; mSynsetReference = null; setLexname(response.getString(3)); getSynset().setLexname(getLexname()); if (!response.isNull(4)) { setMarker(response.getString(4)); } setFreqCnt(response.getInt(5)); JSONArray _synonyms = response.getJSONArray(6); mSynonyms = new ArrayList<Sense>(_synonyms.length()); int j; int senseId; String senseName; for (j = 0; j < _synonyms.length(); ++j) { JSONArray _synonym = _synonyms.getJSONArray(j); senseId = _synonym.getInt(0); senseName = _synonym.getString(1); String marker = null; if (!_synonym.isNull(2)) { marker = _synonym.getString(2); } int freqCnt = _synonym.getInt(3); Sense synonym = new Sense(senseId, senseName, getSynset()); synonym.setMarker(marker); synonym.setFreqCnt(freqCnt); mSynonyms.add(synonym); } JSONArray _verbFrames = response.getJSONArray(7); mVerbFrames = new ArrayList<String>(_verbFrames.length()); for (j = 0; j < _verbFrames.length(); ++j) { String frame = _verbFrames.getString(j); // Replace %s in verb frames with the name of the word // TODO: Make that a bold span. StringBuffer buffer = new StringBuffer(); Formatter formatter = new Formatter(buffer); formatter.format(frame, new Object[] { getName() }); formatter.close(); mVerbFrames.add(buffer.toString()); } JSONArray _samples = response.getJSONArray(8); mSamples = new ArrayList<String>(_samples.length()); for (j = 0; j < _samples.length(); ++j) { mSamples.add(_samples.getString(j)); } parsePointers(response.getJSONArray(9)); }
From source file:org.liberty.android.fantastischmemopro.downloader.DownloaderSS.java
private void downloadDatabase(DownloadItem di) throws Exception { String url = di.getAddress(); String jsonString = downloadJSONString(url); JSONObject jsonObject = new JSONObject(jsonString); JSONArray jsonDataArray = jsonObject.getJSONArray("data"); List<Item> itemList = new LinkedList<Item>(); for (int i = 0; i < jsonDataArray.length(); i++) { JSONArray jsonItemArray = jsonDataArray.getJSONArray(i); String question = jsonItemArray.getString(0); String answer = jsonItemArray.getString(1); if (question != null && !question.equals("")) { Item item = new Item(); item.setQuestion(question);//from w w w . j a va2s.c om item.setAnswer(answer); item.setId(i + 1); itemList.add(item); } } String dbname = di.getTitle() + ".db"; String dbpath = Environment.getExternalStorageDirectory().getAbsolutePath() + getString(R.string.default_dir); DatabaseHelper.createEmptyDatabase(dbpath, dbname); DatabaseHelper dbHelper = new DatabaseHelper(this, dbpath, dbname); dbHelper.insertListItems(itemList); dbHelper.close(); }
From source file:com.hichinaschool.flashcards.anki.StudyOptionsFragment.java
private void createFilteredDeck(JSONArray delays, Object[] terms, Boolean resched) { JSONObject dyn;// ww w. j a v a 2 s. co m if (AnkiDroidApp.colIsOpen()) { Collection col = AnkiDroidApp.getCol(); try { String deckName = col.getDecks().current().getString("name"); String customStudyDeck = getResources().getString(R.string.custom_study_deck_name); JSONObject cur = col.getDecks().byName(customStudyDeck); if (cur != null) { if (cur.getInt("dyn") != 1) { StyledDialog.Builder builder = new StyledDialog.Builder(getActivity()); builder.setMessage(R.string.custom_study_deck_exists); builder.setNegativeButton(getResources().getString(R.string.cancel), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // } }); builder.create().show(); return; } else { // safe to empty col.getSched().emptyDyn(cur.getLong("id")); // reuse; don't delete as it may have children dyn = cur; col.getDecks().select(cur.getLong("id")); } } else { long did = col.getDecks().newDyn(customStudyDeck); dyn = col.getDecks().get(did); } // and then set various options dyn.put("delays", delays); JSONArray ar = dyn.getJSONArray("terms"); ar.getJSONArray(0).put(0, new StringBuilder("deck:\"").append(deckName).append("\" ").append(terms[0]).toString()); ar.getJSONArray(0).put(1, terms[1]); ar.getJSONArray(0).put(2, terms[2]); dyn.put("resched", resched); if (mFragmented) { Bundle config = new Bundle(); config.putString("searchSuffix", "'deck:" + dyn.getString("name") + "'"); initAllContentViews(getLayoutInflater(config)); finishCongrats(); } else { // Load a new fragment with the filtered deck view. The config passed is null, so it uses the // current deck. The deck we just created is internally set as the current deck. ((StudyOptionsActivity) getActivity()).loadContent(false, null); } // Initial rebuild mProgressDialog = StyledProgressDialog.show(getActivity(), "", getResources().getString(R.string.rebuild_custom_study_deck), true); DeckTask.launchDeckTask(DeckTask.TASK_TYPE_REBUILD_CRAM, mRebuildCustomStudyListener, new DeckTask.TaskData(AnkiDroidApp.getCol(), AnkiDroidApp.getCol().getDecks().selected(), mFragmented)); } catch (JSONException e) { throw new RuntimeException(e); } } }
From source file:run.ace.IncomingMessages.java
public static Object create(JSONArray message, Activity activity) throws JSONException { String fullTypeName = message.getString(2); Class c = null;// w w w. j a v a2 s. c o m Object instance = null; try { c = Class.forName(fullTypeName); } catch (ClassNotFoundException e) { throw new RuntimeException("Unable to find a class named '" + fullTypeName + "'"); } if (message.length() == 4) { // Parameterized constructor JSONArray constructorArgs = message.getJSONArray(3); Object[] args = Utils.convertJSONArrayToArray(constructorArgs); instance = Utils.invokeConstructorWithBestParameterMatch(c, args); } else { // Default constructor try { // Expect the Context constructor try { instance = c.getConstructor(new Class[] { Context.class }).newInstance(activity); } catch (NoSuchMethodException ex) { // Try the default constructor instead instance = c.getConstructor().newInstance(); } } catch (NoSuchMethodException ex) { throw new RuntimeException(fullTypeName + " does not have a public default constructor, or a public constructor with a single Context parameter"); } catch (InvocationTargetException ex) { throw new RuntimeException( "Error in " + fullTypeName + " constructor: " + ex.getTargetException().toString()); } catch (IllegalAccessException ex) { throw new RuntimeException(fullTypeName + ", or its relevant constructor, isn't public"); } catch (InstantiationException ex) { throw new RuntimeException("Error instantiating " + fullTypeName + ": " + ex.toString()); } } return instance; }
From source file:run.ace.IncomingMessages.java
public static Object invoke(JSONArray message) throws JSONException { Object instance = Handle.deserialize(message.getJSONObject(1)); String methodName = message.getString(2); JSONArray array = message.getJSONArray(3); return Utils.invokeMethod(instance.getClass(), instance, methodName, array); }
From source file:run.ace.IncomingMessages.java
public static Object staticInvoke(JSONArray message) throws JSONException { String fullTypeName = message.getString(1); String methodName = message.getString(2); JSONArray array = message.getJSONArray(3); Class c = null;//ww w .j a v a2s . com try { c = Class.forName(fullTypeName); } catch (ClassNotFoundException e) { throw new RuntimeException("Unable to find a class named '" + fullTypeName + "'"); } return Utils.invokeMethod(c, null, methodName, array); }
From source file:com.liferay.mobile.android.v62.contact.ContactService.java
public JSONArray getContacts(long classNameId, long classPK, int start, int end, JSONObjectWrapper orderByComparator) throws Exception { JSONObject _command = new JSONObject(); try {//from w ww. jav a 2 s. c o m JSONObject _params = new JSONObject(); _params.put("classNameId", classNameId); _params.put("classPK", classPK); _params.put("start", start); _params.put("end", end); mangleWrapper(_params, "orderByComparator", "com.liferay.portal.kernel.util.OrderByComparator", orderByComparator); _command.put("/contact/get-contacts", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getJSONArray(0); }