List of usage examples for org.json JSONObject getLong
public long getLong(String key) throws JSONException
From source file:com.hichinaschool.flashcards.libanki.Decks.java
/** Add or update an existing deck. Used for syncing and merging. */ public void update(JSONObject g) { try {//from www . ja va2 s. com mDecks.put(g.getLong("id"), g); } catch (JSONException e) { throw new RuntimeException(e); } maybeAddToActive(); // mark registry changed, but don't bump mod time save(); }
From source file:com.hichinaschool.flashcards.libanki.Decks.java
public JSONObject confForDid(long did) { JSONObject deck = get(did); if (deck.has("conf")) { try {//w ww .ja v a 2 s . co m JSONObject conf = getConf(deck.getLong("conf")); conf.put("dyn", 0); return conf; } catch (JSONException e) { throw new RuntimeException(e); } } // dynamic decks have embedded conf return deck; }
From source file:com.hichinaschool.flashcards.libanki.Decks.java
public void updateConf(JSONObject g) { try {/* www. j a va2 s. co m*/ mDconf.put(g.getLong("id"), g); } catch (JSONException e) { throw new RuntimeException(e); } save(); }
From source file:com.hichinaschool.flashcards.libanki.Decks.java
public ArrayList<Long> didsForConf(JSONObject conf) { ArrayList<Long> dids = new ArrayList<Long>(); Iterator<JSONObject> it = mDecks.values().iterator(); try {// w w w . ja va2s. co m while (it.hasNext()) { JSONObject deck = it.next(); if (deck.has("conf") && deck.getLong("conf") == conf.getLong("id")) { dids.add(deck.getLong("id")); } } return dids; } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:com.hichinaschool.flashcards.libanki.Decks.java
public void restoreToDefault(JSONObject conf) { try {//from w w w . j a va 2s. c o m int oldOrder = conf.getJSONObject("new").getInt("order"); JSONObject newConf = new JSONObject(defaultConf); newConf.put("id", conf.getLong("id")); newConf.put("name", conf.getString("name")); mDconf.put(conf.getLong("id"), newConf); save(newConf); // if it was previously randomized, resort if (oldOrder == 0) { mCol.getSched().resortConf(newConf); } } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:com.hichinaschool.flashcards.libanki.Decks.java
private void maybeAddToActive() { // reselect current deck, or default if current has disappeared JSONObject c = current(); try {/*from w w w . ja v a2 s .co m*/ select(c.getLong("id")); } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:com.hichinaschool.flashcards.libanki.Decks.java
public TreeMap<String, Long> children(long did) { String name;/*from w ww . j ava 2 s. com*/ try { name = get(did).getString("name"); TreeMap<String, Long> list = new TreeMap<String, Long>(); for (JSONObject g : all()) { if (g.getString("name").startsWith(name + "::")) { list.put(g.getString("name"), g.getLong("id")); } } return list; } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:com.creationgroundmedia.popularmovies.sync.MovieSyncAdapter.java
private void getMovieDataFromJson(String movieJsonStr) throws JSONException { if (movieJsonStr == null) { return;/*from w w w.ja v a 2s .c om*/ } JSONObject movieJSON = new JSONObject(movieJsonStr); JSONArray movieList = movieJSON.getJSONArray(mContext.getString(R.string.jsonresults)); Vector<ContentValues> cvVector = new Vector<ContentValues>(movieList.length()); for (int i = 0; i < movieList.length(); i++) { JSONObject titleJSON = movieList.getJSONObject(i); ContentValues movieValues = new ContentValues(); String title = titleJSON.getString(mContext.getString(R.string.jsontitle)); movieValues.put(MoviesContract.MovieEntry.COLUMN_ADULT, titleJSON.getBoolean(mContext.getString(R.string.jsonadult)) ? 1 : 0); movieValues.put(MoviesContract.MovieEntry.COLUMN_BACKDROP_PATH, titleJSON.getString(mContext.getString(R.string.jsonbackdrop))); movieValues.put(MoviesContract.MovieEntry.COLUMN_FAVORITE, 0); movieValues.put(MoviesContract.MovieEntry.COLUMN_FRESH, 1); movieValues.put(MoviesContract.MovieEntry.COLUMN_ID_KEY, titleJSON.getLong(mContext.getString(R.string.jsonid))); movieValues.put(MoviesContract.MovieEntry.COLUMN_ORIGINAL_LANGUAGE, titleJSON.getString(mContext.getString(R.string.jsonoriginallanguage))); movieValues.put(MoviesContract.MovieEntry.COLUMN_OVERVIEW, titleJSON.getString(mContext.getString(R.string.jsonoverview))); movieValues.put(MoviesContract.MovieEntry.COLUMN_POPULARITY, titleJSON.getString(mContext.getString(R.string.jsonpopularity))); movieValues.put(MoviesContract.MovieEntry.COLUMN_POSTER_PATH, titleJSON.getString(mContext.getString(R.string.jsonposter))); movieValues.put(MoviesContract.MovieEntry.COLUMN_RELEASE_DATE, titleJSON.getString(mContext.getString(R.string.jsondate))); movieValues.put(MoviesContract.MovieEntry.COLUMN_SORTTITLE, trimLeadingThe(title)); movieValues.put(MoviesContract.MovieEntry.COLUMN_TITLE, title); movieValues.put(MoviesContract.MovieEntry.COLUMN_VIDEO, titleJSON.getBoolean(mContext.getString(R.string.jsonvideo)) ? 1 : 0); movieValues.put(MoviesContract.MovieEntry.COLUMN_VOTE_AVERAGE, titleJSON.getString(mContext.getString(R.string.jsonvoteaverage))); movieValues.put(MoviesContract.MovieEntry.COLUMN_VOTE_COUNT, titleJSON.getInt(mContext.getString(R.string.jsonvotecount))); cvVector.add(movieValues); } ContentValues[] cvArray = new ContentValues[cvVector.size()]; cvVector.toArray(cvArray); int inserted = mContext.getContentResolver().bulkInsert(MoviesContract.MovieEntry.CONTENT_URI, cvArray); }
From source file:com.miz.apis.trakt.Show.java
public Show(JSONObject summaryJson) { try {/*from w w w .j a v a2 s . c o m*/ mTitle = summaryJson.getString("title"); mYear = summaryJson.getInt("year"); mUrl = summaryJson.getString("url"); mFirstAired = summaryJson.getLong("first_aired"); mCountry = summaryJson.getString("country"); mOverview = summaryJson.getString("overview"); mRuntime = summaryJson.getInt("runtime"); mStatus = summaryJson.getString("status"); mNetwork = summaryJson.getString("network"); mAirDay = summaryJson.getString("air_day"); mAirTime = summaryJson.getString("air_time"); mCertification = summaryJson.getString("certification"); mImdbId = summaryJson.getString("imdb_id"); mTvdbId = summaryJson.getInt("tvdb_id"); mTvRageId = summaryJson.getInt("tvrage_id"); mPoster = summaryJson.getString("poster"); mFanart = summaryJson.getJSONObject("images").getString("fanart"); mRating = summaryJson.getJSONObject("ratings").getInt("percentage"); JSONArray genres = summaryJson.getJSONArray("genres"); for (int i = 0; i < genres.length(); i++) mGenres.add(genres.getString(i)); } catch (JSONException e) { } }
From source file:com.daskiworks.ghwatch.backend.WatchedRepositoriesParser.java
public static WatchedRepositories parseNotificationStream(JSONArray json) throws InvalidObjectException { WatchedRepositories ret = new WatchedRepositories(); try {/* w w w .j ava2s .c o m*/ for (int i = 0; i < json.length(); i++) { JSONObject repository = json.getJSONObject(i); JSONObject owner = repository.getJSONObject("owner"); ret.addRepository(new Repository(repository.getLong("id"), repository.getString("url"), repository.getString("full_name"), owner.getString("avatar_url"), repository.getString("html_url"))); } } catch (Exception e) { throw new InvalidObjectException("JSON message is invalid: " + e.getMessage()); } return ret; }