List of usage examples for org.json JSONObject getDouble
public double getDouble(String key) throws JSONException
From source file:edu.asu.bscs.csiebler.waypointapplication.Waypoint.java
/** * Constructor//from w ww. j a v a 2s. c o m * * @param jsonString */ public Waypoint(String jsonString) { try { System.out.println("constructor from json received: " + jsonString); JSONObject obj = new JSONObject(jsonString); latitude = obj.getDouble("lat"); longitude = obj.getDouble("lon"); elevation = obj.getDouble("ele"); name = obj.getString("name"); address = obj.getString("address"); category = Category.valueOf(obj.getString("category")); System.out.println("constructed " + this.toJsonString() + " from json"); } catch (Exception ex) { System.out.println("Exception constructing waypoint from string: " + ex.getMessage()); } }
From source file:com.soomla.store.domain.MarketItem.java
/** * Constructor./*w ww . j av a 2s . co m*/ * Generates an instance of <code>MarketItem</code> from a <code>JSONObject</code>. * * @param jsonObject a <code>JSONObject</code> representation of the wanted * <code>MarketItem</code>. * @throws JSONException */ public MarketItem(JSONObject jsonObject) throws JSONException { if (jsonObject.has(StoreJSONConsts.MARKETITEM_MANAGED)) { this.mManaged = Managed.values()[jsonObject.getInt(StoreJSONConsts.MARKETITEM_MANAGED)]; } else { this.mManaged = Managed.UNMANAGED; } if (jsonObject.has(StoreJSONConsts.MARKETITEM_ANDROID_ID)) { this.mProductId = jsonObject.getString(StoreJSONConsts.MARKETITEM_ANDROID_ID); } else { this.mProductId = jsonObject.getString(StoreJSONConsts.MARKETITEM_PRODUCT_ID); } this.mPrice = jsonObject.getDouble(StoreJSONConsts.MARKETITEM_PRICE); this.mMarketPrice = jsonObject.optString(StoreJSONConsts.MARKETITEM_MARKETPRICE); this.mMarketTitle = jsonObject.optString(StoreJSONConsts.MARKETITEM_MARKETTITLE); this.mMarketDescription = jsonObject.optString(StoreJSONConsts.MARKETITEM_MARKETDESC); }
From source file:org.marietjedroid.connect.MarietjeTrack.java
/** * @param media//from www .j av a2 s.c om */ public MarietjeTrack(JSONObject media) { try { this.artist = media.getString("artist"); this.title = media.getString("title"); this.trackKey = media.getString("key"); this.uploadedBy = media.getString("uploadedByKey"); this.length = media.getDouble("length"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.google.android.apps.santatracker.service.APIProcessor.java
private int processRoute(JSONArray json) { SQLiteDatabase db = mDestinationDBHelper.getWritableDatabase(); db.beginTransaction();//from w w w. j a va 2 s. co m try { // loop over each destination long previousPresents = mPreferences.getTotalPresents(); int i; for (i = 0; i < json.length(); i++) { JSONObject dest = json.getJSONObject(i); JSONObject location = dest.getJSONObject(FIELD_DETAILS_LOCATION); long presentsTotal = dest.getLong(FIELD_DETAILS_PRESENTSDELIVERED); long presents = presentsTotal - previousPresents; previousPresents = presentsTotal; // Name String city = dest.getString(FIELD_DETAILS_CITY); String region = null; String country = null; if (dest.has(FIELD_DETAILS_REGION)) { region = dest.getString(FIELD_DETAILS_REGION); if (region.length() < 1) { region = null; } } if (dest.has(FIELD_DETAILS_COUNTRY)) { country = dest.getString(FIELD_DETAILS_COUNTRY); if (country.length() < 1) { country = null; } } // if (mDebugLog) { // Log.d(TAG, "Location: " + city); // } // Detail fields JSONObject details = dest.getJSONObject(FIELD_DETAILS_DETAILS); long timezone = details.isNull(FIELD_DETAILS_TIMEZONE) ? 0L : details.getLong(FIELD_DETAILS_TIMEZONE); long altitude = details.getLong(FIELD_DETAILS_ALTITUDE); String photos = details.has(FIELD_DETAILS_PHOTOS) ? details.getString(FIELD_DETAILS_PHOTOS) : EMPTY_STRING; String weather = details.has(FIELD_DETAILS_WEATHER) ? details.getString(FIELD_DETAILS_WEATHER) : EMPTY_STRING; String streetview = details.has(FIELD_DETAILS_STREETVIEW) ? details.getString(FIELD_DETAILS_STREETVIEW) : EMPTY_STRING; String gmmStreetview = details.has(FIELD_DETAILS_GMMSTREETVIEW) ? details.getString(FIELD_DETAILS_GMMSTREETVIEW) : EMPTY_STRING; try { // All parsed, insert into DB mDestinationDBHelper.insertDestination(db, dest.getString(FIELD_IDENTIFIER), dest.getLong(FIELD_ARRIVAL), dest.getLong(FIELD_DEPARTURE), city, region, country, location.getDouble(FIELD_DETAILS_LOCATION_LAT), location.getDouble(FIELD_DETAILS_LOCATION_LNG), presentsTotal, presents, timezone, altitude, photos, weather, streetview, gmmStreetview); } catch (android.database.sqlite.SQLiteConstraintException e) { // ignore duplicate locations } } db.setTransactionSuccessful(); // Update mPreferences mPreferences.setDBTimestamp(System.currentTimeMillis()); mPreferences.setTotalPresents(previousPresents); return i; } catch (JSONException e) { Log.d(TAG, "Santa location tracking error 30"); SantaLog.d(TAG, "JSON Exception", e); } finally { db.endTransaction(); } return 0; }
From source file:com.google.android.apps.santatracker.service.APIProcessor.java
/** * Returns the double of the JSON object identified by the name. Returns {@link * java.lang.Double#MAX_VALUE} if the field does not exist. *///from w w w. java2 s. co m public static double getExistingJSONDouble(JSONObject json, String name) throws JSONException { if (json.has(name)) { return json.getDouble(name); } else { return Double.MAX_VALUE; } }
From source file:fr.pasteque.client.sync.SyncUpdate.java
private void parseTaxes(JSONObject resp) { try {/*from w w w.ja v a2 s. com*/ JSONArray array = resp.getJSONArray("content"); for (int i = 0; i < array.length(); i++) { JSONObject taxCat = array.getJSONObject(i); String taxCatId = taxCat.getString("id"); JSONArray taxes = taxCat.getJSONArray("taxes"); long now = System.currentTimeMillis() / 1000; int index = 0; long maxDate = 0; for (int j = 0; j < taxes.length(); j++) { JSONObject tax = taxes.getJSONObject(j); long date = tax.getLong("startDate"); if (date > maxDate && date < now) { index = j; maxDate = date; } } JSONObject currentTax = taxes.getJSONObject(index); double rate = currentTax.getDouble("rate"); String id = currentTax.getString("id"); this.taxRates.put(taxCatId, rate); this.taxIds.put(taxCatId, id); } } catch (JSONException e) { Log.e(LOG_TAG, "Unable to parse response: " + resp.toString(), e); SyncUtils.notifyListener(this.listener, TAXES_SYNC_ERROR, e); this.taxesDone = true; this.productsDone = true; this.compositionsDone = true; return; } SyncUtils.notifyListener(this.listener, TAXES_SYNC_DONE, this.taxRates); // Start synchronizing catalog URLTextGetter.getText(SyncUtils.apiUrl(this.ctx), SyncUtils.initParams(this.ctx, "CategoriesAPI", "getAll"), new DataHandler(DataHandler.TYPE_CATEGORY)); }
From source file:com.graphhopper.http.NominatimGeocoder.java
@Override public List<GHPlace> names2places(GHPlace... places) { List<GHPlace> resList = new ArrayList<GHPlace>(); for (GHPlace place : places) { // see https://trac.openstreetmap.org/ticket/4683 why limit=3 and not 1 String url = nominatimUrl + "?format=json&q=" + WebHelper.encodeURL(place.getName()) + "&limit=3"; if (bounds != null) { // minLon, minLat, maxLon, maxLat => left, top, right, bottom url += "&bounded=1&viewbox=" + bounds.minLon + "," + bounds.maxLat + "," + bounds.maxLon + "," + bounds.minLat;/*from www . j ava 2 s.c o m*/ } try { HttpURLConnection hConn = openConnection(url); String str = WebHelper.readString(hConn.getInputStream()); // System.out.println(str); // TODO sort returned objects by bounding box area size? JSONObject json = new JSONArray(str).getJSONObject(0); double lat = json.getDouble("lat"); double lon = json.getDouble("lon"); GHPlace p = new GHPlace(lat, lon); p.setName(json.getString("display_name")); resList.add(p); } catch (Exception ex) { logger.error("problem while geocoding (search " + place + "): " + ex.getMessage()); } } return resList; }
From source file:com.graphhopper.http.NominatimGeocoder.java
@Override public List<GHPlace> places2names(GHPlace... points) { List<GHPlace> resList = new ArrayList<GHPlace>(); for (GHPlace point : points) { try {//from w w w . j a v a2 s. c o m String url = nominatimReverseUrl + "?lat=" + point.lat + "&lon=" + point.lon + "&format=json&zoom=16"; HttpURLConnection hConn = openConnection(url); String str = WebHelper.readString(hConn.getInputStream()); // System.out.println(str); JSONObject json = new JSONObject(str); double lat = json.getDouble("lat"); double lon = json.getDouble("lon"); JSONObject address = json.getJSONObject("address"); String name = ""; if (address.has("road")) { name += address.get("road") + ", "; } if (address.has("postcode")) { name += address.get("postcode") + " "; } if (address.has("city")) { name += address.get("city") + ", "; } else if (address.has("county")) { name += address.get("county") + ", "; } if (address.has("state")) { name += address.get("state") + ", "; } if (address.has("country")) { name += address.get("country"); } resList.add(new GHPlace(lat, lon).setName(name)); } catch (Exception ex) { logger.error("problem while geocoding (reverse " + point + "): " + ex.getMessage()); } } return resList; }
From source file:org.mixare.data.Json.java
public Marker processMixareJSONObject(JSONObject jo, DataSource datasource, MixContext ctx) throws JSONException { Marker ma = null;//from w w w. j av a2 s .co m if (jo.has("title") && jo.has("lat") && jo.has("lng") && jo.has("elevation")) { Log.v(MixView.TAG, "processing Mixare JSON object"); String link = null; if (jo.has("has_detail_page") && jo.getInt("has_detail_page") != 0 && jo.has("webpage")) link = jo.getString("webpage"); if (jo.has("type")) { // jo.getDouble("elevation") if (jo.getString("type").equals("POI")) { System.out.println( "create marker poi: " + jo.getString("title") + "ele: " + jo.getDouble("elevation")); ma = new POIMarker(unescapeHTML(jo.getString("title"), 0), jo.getDouble("lat"), jo.getDouble("lng"), 0, link, datasource); } else if (jo.getString("type").equals("SPECIAL_POI")) { System.out.println("create marker special poi"); ma = new SpecialPOIMarker(unescapeHTML(jo.getString("title").replace("Route to ", ""), 0), jo.getDouble("lat"), jo.getDouble("lng"), 0, link, datasource); } else if (jo.getString("type").equals("FRIEND")) { System.out.println("create marker friend"); ma = new FriendMarker(unescapeHTML(jo.getString("title"), 0), jo.getDouble("lat"), jo.getDouble("lng"), 0, link, datasource, ctx); } else if (jo.getString("type").equals("GRAFFITI")) { System.out.println("create marker graffiti"); ma = new GraffitiMarker(unescapeHTML(jo.getString("title"), 0), jo.getDouble("lat"), jo.getDouble("lng"), 0, link, datasource, Json.getRandomGraffitiColor()); } else if (jo.getString("type").equals("ARROW")) { System.out.println("create marke arrow"); ma = new NavigationMarker(unescapeHTML(jo.getString("title"), 0), jo.getDouble("lat"), jo.getDouble("lng"), 0, link, datasource); } } else { } // if(!(datasource.getDisplay() == DataSource.DISPLAY.CIRCLE_MARKER)) { // Log.v(MixView.TAG, "adding Mixare JSON object"); // ma = new POIMarker( // unescapeHTML(jo.getString("title"), 0), // jo.getDouble("lat"), // jo.getDouble("lng"), // jo.getDouble("elevation"), // link, // datasource); // } else { // Log.v(MixView.TAG, "adding Mixare JSON object (else)"); // ma = new NavigationMarker( // unescapeHTML(jo.getString("title"), 0), // jo.getDouble("lat"), // jo.getDouble("lng"), // 0, // link, // datasource); // } } return ma; }
From source file:org.mixare.data.Json.java
public Marker processWikipediaJSONObject(JSONObject jo, DataSource datasource) throws JSONException { Marker ma = null;//from w w w . j a va 2 s .c o m if (jo.has("title") && jo.has("lat") && jo.has("lng") && jo.has("elevation") && jo.has("wikipediaUrl")) { Log.v(MixView.TAG, "processing Wikipedia JSON object"); ma = new POIMarker(unescapeHTML(jo.getString("title"), 0), jo.getDouble("lat"), jo.getDouble("lng"), jo.getDouble("elevation"), "http://" + jo.getString("wikipediaUrl"), datasource); } return ma; }