List of usage examples for org.json JSONObject getDouble
public double getDouble(String key) throws JSONException
From source file:edu.mbl.jif.imaging.mmtiff.MultipageTiffWriter.java
private void processSummaryMD(JSONObject summaryMD) throws MMScriptException, JSONException { rgb_ = MDUtils.isRGB(summaryMD);/*from w ww.j a v a 2 s .com*/ numChannels_ = MDUtils.getNumChannels(summaryMD); numFrames_ = MDUtils.getNumFrames(summaryMD); numSlices_ = MDUtils.getNumSlices(summaryMD); imageWidth_ = MDUtils.getWidth(summaryMD); imageHeight_ = MDUtils.getHeight(summaryMD); String pixelType = MDUtils.getPixelType(summaryMD); if (pixelType.equals("GRAY8") || pixelType.equals("RGB32") || pixelType.equals("RGB24")) { byteDepth_ = 1; } else if (pixelType.equals("GRAY16") || pixelType.equals("RGB64")) { byteDepth_ = 2; } else if (pixelType.equals("GRAY32")) { byteDepth_ = 3; } else { byteDepth_ = 2; } bytesPerImagePixels_ = imageHeight_ * imageWidth_ * byteDepth_ * (rgb_ ? 3 : 1); //Tiff resolution tag values double cmPerPixel = 0.0001; if (summaryMD.has("PixelSizeUm")) { try { cmPerPixel = 0.0001 * summaryMD.getDouble("PixelSizeUm"); } catch (JSONException ex) { } } else if (summaryMD.has("PixelSize_um")) { try { cmPerPixel = 0.0001 * summaryMD.getDouble("PixelSize_um"); } catch (JSONException ex) { } } double log = Math.log10(cmPerPixel); if (log >= 0) { resDenomenator_ = (long) cmPerPixel; resNumerator_ = 1; } else { resNumerator_ = (long) (1 / cmPerPixel); resDenomenator_ = 1; } if (summaryMD.has("z-step_um") && !summaryMD.isNull("z-step_um")) { zStepUm_ = summaryMD.getDouble("z-step_um"); } }
From source file:edu.mbl.jif.imaging.mmtiff.MultipageTiffWriter.java
/** * writes channel LUTs and display ranges for composite mode Could also be * expanded to write ROIs, file info, slice labels, and overlays */// w ww . j a va 2 s . c o m private void writeImageJMetadata(int numChannels, String summaryComment) throws IOException { String info = summaryMDString_; if (summaryComment != null && summaryComment.length() > 0) { info = "Acquisition comments: \n" + summaryComment + "\n\n\n" + summaryMDString_; } //size entry (4 bytes) + 4 bytes file info size + 4 bytes for channel display //ranges length + 4 bytes per channel LUT int mdByteCountsBufferSize = 4 + 4 + 4 + 4 * numChannels; int bufferPosition = 0; ByteBuffer mdByteCountsBuffer = ByteBuffer.allocate(mdByteCountsBufferSize).order(BYTE_ORDER); //nTypes is number actually written among: fileInfo, slice labels, display ranges, channel LUTS, //slice labels, ROI, overlay, and # of extra metadata entries int nTypes = 3; //file info, display ranges, and channel LUTs int mdBufferSize = 4 + nTypes * 8; //Header size: 4 bytes for magic number + 8 bytes for label (int) and count (int) of each type mdByteCountsBuffer.putInt(bufferPosition, 4 + nTypes * 8); bufferPosition += 4; //2 bytes per a character of file info mdByteCountsBuffer.putInt(bufferPosition, 2 * info.length()); bufferPosition += 4; mdBufferSize += info.length() * 2; //display ranges written as array of doubles (min, max, min, max, etc) mdByteCountsBuffer.putInt(bufferPosition, numChannels * 2 * 8); bufferPosition += 4; mdBufferSize += numChannels * 2 * 8; for (int i = 0; i < numChannels; i++) { //768 bytes per LUT mdByteCountsBuffer.putInt(bufferPosition, 768); bufferPosition += 4; mdBufferSize += 768; } //Header (1) File info (1) display ranges (1) LUTS (1 per channel) int numMDEntries = 3 + numChannels; ByteBuffer ifdCountAndValueBuffer = ByteBuffer.allocate(8).order(BYTE_ORDER); ifdCountAndValueBuffer.putInt(0, numMDEntries); ifdCountAndValueBuffer.putInt(4, (int) filePosition_); fileChannel_.write(ifdCountAndValueBuffer, ijMetadataCountsTagPosition_ + 4); fileChannel_.write(mdByteCountsBuffer, filePosition_); filePosition_ += mdByteCountsBufferSize; //Write metadata types and counts ByteBuffer mdBuffer = ByteBuffer.allocate(mdBufferSize).order(BYTE_ORDER); bufferPosition = 0; //All the ints declared below are non public field in TiffDecoder final int ijMagicNumber = 0x494a494a; mdBuffer.putInt(bufferPosition, ijMagicNumber); bufferPosition += 4; //Write ints for each IJ metadata field and its count final int fileInfo = 0x696e666f; mdBuffer.putInt(bufferPosition, fileInfo); bufferPosition += 4; mdBuffer.putInt(bufferPosition, 1); bufferPosition += 4; final int displayRanges = 0x72616e67; mdBuffer.putInt(bufferPosition, displayRanges); bufferPosition += 4; mdBuffer.putInt(bufferPosition, 1); bufferPosition += 4; final int luts = 0x6c757473; mdBuffer.putInt(bufferPosition, luts); bufferPosition += 4; mdBuffer.putInt(bufferPosition, numChannels); bufferPosition += 4; //write actual metadata //FileInfo for (char c : info.toCharArray()) { mdBuffer.putChar(bufferPosition, c); bufferPosition += 2; } try { JSONArray channels = masterMPTiffStorage_.getDisplayAndComments().getJSONArray("Channels"); JSONObject channelSetting; for (int i = 0; i < numChannels; i++) { channelSetting = channels.getJSONObject(i); //Display Ranges: For each channel, write min then max mdBuffer.putDouble(bufferPosition, channelSetting.getInt("Min")); bufferPosition += 8; mdBuffer.putDouble(bufferPosition, channelSetting.getInt("Max")); bufferPosition += 8; } //LUTs for (int i = 0; i < numChannels; i++) { channelSetting = channels.getJSONObject(i); LUT lut = ImageUtils.makeLUT(new Color(channelSetting.getInt("Color")), channelSetting.getDouble("Gamma")); for (byte b : lut.getBytes()) { mdBuffer.put(bufferPosition, b); bufferPosition++; } } } catch (JSONException ex) { ReportingUtils.logError( "Problem with displayAndComments: Couldn't write ImageJ display settings as a result"); } ifdCountAndValueBuffer = ByteBuffer.allocate(8).order(BYTE_ORDER); ifdCountAndValueBuffer.putInt(0, mdBufferSize); ifdCountAndValueBuffer.putInt(4, (int) filePosition_); fileChannel_.write(ifdCountAndValueBuffer, ijMetadataTagPosition_ + 4); fileChannel_.write(mdBuffer, filePosition_); filePosition_ += mdBufferSize; }
From source file:com.gmail.at.faint545.adapters.RemoteQueueAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = ((LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE)) .inflate(resourceID, null); ViewHolder viewHolder = new ViewHolder(); viewHolder.filename = (TextView) convertView.findViewById(R.id.remote_queue_row_filename); viewHolder.status = (TextView) convertView.findViewById(R.id.remote_queue_row_status); viewHolder.checkBox = (CheckBox) convertView.findViewById(R.id.remote_queue_checkbox); viewHolder.progressBar = (ProgressBar) convertView.findViewById(R.id.remote_queue_progress_bar); convertView.setTag(viewHolder);//from ww w .j av a 2 s . c o m } JSONObject job = jobs.get(position); if (job != null) { ViewHolder viewHolder = (ViewHolder) convertView.getTag(); StringBuilder jobStatus = new StringBuilder(); String statusText = null, filename = null; double mbLeft = 0, mbTotal = 0; Boolean isChecked = false; try { mbLeft = job.getDouble(SabnzbdConstants.MBLEFT); mbTotal = job.getDouble(SabnzbdConstants.MB); statusText = job.getString(SabnzbdConstants.STATUS); filename = job.getString(SabnzbdConstants.FILENAME); isChecked = job.getBoolean("checked"); } catch (JSONException e) { // Do nothing } jobStatus.append(statusText).append(", ").append(StringUtils.normalizeSize(mbLeft, "m")) .append(" left of ").append(StringUtils.normalizeSize(mbTotal, "m")); viewHolder.checkBox.setChecked(isChecked); viewHolder.filename.setText(filename); viewHolder.status.setText(jobStatus.toString()); viewHolder.progressBar.setMax((int) mbTotal); viewHolder.progressBar.setProgress((int) (mbTotal - mbLeft)); } return convertView; }
From source file:com.prashantpal.sunshine.app.FetchWeatherTask.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us./*from w w w .j a va2 s. co m*/ */ private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting) throws JSONException { // Now we have a String representing the complete forecast in JSON Format. // Fortunately parsing is easy: constructor takes the JSON string and converts it // into an Object hierarchy for us. // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; // Location coordinate final String OWM_LATITUDE = "lat"; final String OWM_LONGITUDE = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; try { JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD); double cityLatitude = cityCoord.getDouble(OWM_LATITUDE); double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE); long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); // OWM returns daily forecasts based upon the local time of the city that is being // asked for, which means that we need to know the GMT offset to translate this data // properly. // Since this data is also sent in-order and the first day is always the // current day, we're going to take advantage of that to get a nice // normalized UTC date for all of our weather. Time dayTime = new Time(); dayTime.setToNow(); // we start at the day returned by local time. Otherwise this is a mess. int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); // now we work exclusively in UTC dayTime = new Time(); int inserted = 0; for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // Cheating to convert this to UTC time, which is what we want anyhow dateTime = dayTime.setJulianDay(julianStartDay + i); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationId); weatherValues.put(WeatherEntry.COLUMN_DATE, dateTime); weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } // add to database if (cVVector.size() > 0) { // Student: call bulkInsert to add the weatherEntries to the database here ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray); } Log.d(LOG_TAG, "FetchWeatherTask Complete. " + inserted + " Inserted"); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:ssc.Sensor.java
/** * Create a new Sensor from a JSON object. * /*w w w . ja va 2 s. c o m*/ * @param obj Sensor data */ public Sensor(JSONObject obj) { String SERIAL = SSCResources.Field.SERIAL; String NAME = SSCResources.Field.NAME; String LOCATION = SSCResources.Field.LOCATION; String LATITUDE = SSCResources.Field.LATITUDE; String LONGITUDE = SSCResources.Field.LONGITUDE; String TYPE_NAME = SSCResources.Field.TYPE_NAME; String DEPLOYED_STATE = SSCResources.Field.DEPLOYED_STATE; String VISIBILITY = SSCResources.Field.VISIBILITY; String INFO = SSCResources.Field.INFO; String DOMAIN = SSCResources.Field.DOMAIN; String CREATED = SSCResources.Field.CREATED; String UPDATED = SSCResources.Field.UPDATED; try { this.serial = (obj.has(SERIAL)) ? obj.getString(SERIAL) : "Not a valid sensor"; this.name = (obj.has(NAME)) ? truncate(obj.getString(NAME), NAME_LENGTH) : ""; this.location = (obj.has(LOCATION)) ? truncate(obj.getString(LOCATION), LOCATION_LENGTH) : ""; this.position = (obj.has(LATITUDE) && obj.has(LONGITUDE)) ? new SSCPosition(obj.getDouble(LATITUDE), obj.getDouble(LONGITUDE)) : new SSCPosition(0.0, 0.0); this.type_name = (obj.has(TYPE_NAME)) ? SSCResources.TypeName.getState(obj.getString(TYPE_NAME)) : SSCResources.TypeName.FREETEXT; this.deployed_state = (obj.has(DEPLOYED_STATE)) ? SSCResources.DeployedState.getState(obj.getString(DEPLOYED_STATE)) : SSCResources.DeployedState.NOT_DEPLOYED; if (obj.has(VISIBILITY)) { String v = obj.getString(VISIBILITY); this.visibility = (v == "1") ? true : false; } this.info = (obj.has(INFO)) ? truncate(obj.getString(INFO), INFO_LENGTH) : ""; this.domain = (obj.has(DOMAIN)) ? obj.getString(DOMAIN) : ""; this.created = (obj.has(CREATED)) ? new SSCTimeUnit(obj.getString(CREATED)) : new SSCTimeUnit(obj.getString("1970-01-01 00:00:00")); this.updated = (obj.has(UPDATED)) ? new SSCTimeUnit(obj.getString(UPDATED)) : new SSCTimeUnit(obj.getString("1970-01-01 00:00:00")); } catch (org.json.JSONException e) { throw new SSCException.MalformedData(e); } }
From source file:menusearch.json.JSONProcessor.java
/** * /*from ww w . j a v a 2 s .c o m*/ * @param json formated JSON string containing all the information for one recipe * @return Recipe object * @throws IOException * * This method takes a formated json string containing one recipe, parses it, and saves it into a recipe object which is then returned. * **You must call the getRecipeAPI() method prior to calling this method. */ public static Recipe parseRecipe(String json) throws IOException, JSONException { JSONTokener tokenizer = new JSONTokener(json); JSONObject obj = new JSONObject(tokenizer); Recipe r = new Recipe(); JSONObject attribution = obj.getJSONObject("attribution"); Attribution a = new Attribution(); a.setHTML(attribution.getString("html")); a.setUrl(attribution.getString("url")); a.setText(attribution.getString("text")); a.setLogo(attribution.getString("logo")); r.setAttribution(a); JSONArray ingredientList = obj.getJSONArray("ingredientLines"); for (int i = 0; i < ingredientList.length(); i++) { r.addIngredient(ingredientList.getString(i)); } JSONObject flavors = obj.getJSONObject("flavors"); r.setBitterFlavor(flavors.getDouble("Bitter")); r.setMeatyFlavor(flavors.getDouble("Meaty")); r.setPiquantFlavor(flavors.getDouble("Piquant")); r.setSaltyFlavor(flavors.getDouble("Salty")); r.setSourFlavor(flavors.getDouble("Sour")); r.setSweetFlavor(flavors.getDouble("Sweet")); JSONArray nutritionEstimates = obj.getJSONArray("nutritionEstimates"); for (int i = 0; i < nutritionEstimates.length(); i++) { NutritionEstimate nutritionInfo = new NutritionEstimate(); Unit aUnit = new Unit(); JSONObject nutrition = nutritionEstimates.getJSONObject(i); nutritionInfo.setAttribute(nutrition.getString("attribute")); if (nutrition.isNull("description") != true) nutritionInfo.setDescription(nutrition.getString("description")); nutritionInfo.setValue(nutrition.getDouble("value")); JSONObject unit = nutrition.getJSONObject("unit"); aUnit.setAbbreviation(unit.getString("abbreviation")); aUnit.setName(unit.getString("name")); aUnit.setPlural(unit.getString("plural")); aUnit.setPluralAbbreviation(unit.getString("pluralAbbreviation")); nutritionInfo.addUnit(aUnit); r.addNutritionInfo(nutritionInfo); } JSONArray images = obj.getJSONArray("images"); JSONObject imageBySize = images.getJSONObject(0); for (int i = 0; i < images.length(); i++) { if (images.getJSONObject(i).has("hostedLargeUrl")) r.setHostedlargeUrl(images.getJSONObject(i).getString("hostedLargeUrl")); if (images.getJSONObject(i).has("hostedMediumUrl")) r.setHostedMediumUrl(images.getJSONObject(i).getString("hostedMediumUrl")); if (images.getJSONObject(i).has("hostedSmallUrl")) r.setHostedSmallUrl(images.getJSONObject(i).getString("hostedSmallUrl")); } if (obj.has("name")) r.setName(obj.getString("name")); if (obj.has("yield")) r.setYield(obj.getString("yield")); if (obj.has("totalTime")) r.setTotalTime(obj.getString("totalTime")); if (obj.has("attributes")) { JSONObject attributes = obj.getJSONObject("attributes"); if (attributes.has("holiday")) { JSONArray holidays = attributes.getJSONArray("holiday"); for (int i = 0; i < holidays.length(); i++) { r.addholidayToList(holidays.getString(i)); } } if (attributes.has("cuisine")) { JSONArray cuisine = attributes.getJSONArray("cuisine"); for (int i = 0; i < cuisine.length(); i++) { r.addCuisineToList(cuisine.getString(i)); } } } if (obj.has("totalTimeInSeconds")) r.setTimetoCook(obj.getDouble("totalTimeInSeconds")); if (obj.has("rating")) r.setRating(obj.getDouble("rating")); if (obj.has("numberofServings")) r.setNumberOfServings(obj.getDouble("numberOfServings")); if (obj.has("source")) { JSONObject source = obj.getJSONObject("source"); if (source.has("sourceSiteUrl")) r.setSourceSiteUrl(source.getString("sourceSiteUrl")); if (source.has("sourceRecipeUrl")) r.setSourceRecipeUrl(source.getString("sourceRecipeUrl")); if (source.has("sourceDisplayName")) r.setSourceDisplayName(source.getString("sourceDisplayName")); } r.setRecipeID(obj.getString("id")); return r; }
From source file:menusearch.json.JSONProcessor.java
/** *//from w ww. j a v a 2 s . c om * @param JSON string: requires the JSON string of the parameters the user enter for the search * @return RecipeSummaryList: a RecipeSummaryList where it contains information about the recipes that matches the search the user made * @throws java.io.IOException */ public static RecipeSummaryList parseRecipeMatches(String results) throws IOException { CourseList courseList = new CourseList(); RecipeSummaryList list = new RecipeSummaryList(); JSONTokener tokenizer = new JSONTokener(results); JSONObject resultList = new JSONObject(tokenizer); JSONArray matches = resultList.getJSONArray("matches"); for (int i = 0; i < matches.length(); i++) { RecipeSummary r = new RecipeSummary(); JSONObject currentRecipe = matches.getJSONObject(i); JSONObject imageUrls = currentRecipe.getJSONObject("imageUrlsBySize"); String link = "90"; String number = imageUrls.getString(link); r.setImageUrlsBySize(number); String source = (String) currentRecipe.getString("sourceDisplayName"); r.setSourceDisplayName(source); JSONArray listOfIngredients = currentRecipe.getJSONArray("ingredients"); for (int n = 0; n < listOfIngredients.length(); n++) { String currentIngredients = listOfIngredients.getString(n); r.ingredients.add(currentIngredients); } String id = (String) currentRecipe.getString("id"); r.setId(id); String recipe = (String) currentRecipe.get("recipeName"); r.setRecipeName(recipe); JSONArray smallImage = currentRecipe.getJSONArray("smallImageUrls"); for (int l = 0; l < smallImage.length(); l++) { String currentUrl = (String) smallImage.get(l); r.setSmallImageUrls(currentUrl); } int timeInSeconds = (int) currentRecipe.getInt("totalTimeInSeconds"); r.setTotalTimeInSeconds(timeInSeconds); String a = "attributes"; String c = "course"; if (currentRecipe.has(a)) { JSONObject currentAttributes = currentRecipe.getJSONObject(a); if (currentAttributes.has(c)) { for (int j = 0; j < currentAttributes.getJSONArray(c).length(); j++) { String course = currentAttributes.getJSONArray(c).getString(j); courseList.add(course); } r.setCourses(courseList); } } CuisineList cuisineList = new CuisineList(); if (currentRecipe.has(a)) { JSONObject currentAttributes = currentRecipe.getJSONObject(a); if (currentAttributes.has("cuisine")) { for (int j = 0; j < currentAttributes.getJSONArray("cuisine").length(); j++) { String currentCuisine = currentAttributes.getJSONArray("cuisine").getString(j); cuisineList.add(currentCuisine); } r.setCusines(cuisineList); } } String f = "flavors"; JSONObject currentFlavors; if (currentRecipe.has(f) == true) { if (currentRecipe.isNull(f) == false) { currentFlavors = currentRecipe.getJSONObject(f); double saltyRating = currentFlavors.getDouble("salty"); double sourRating = currentFlavors.getDouble("sour"); double sweetRating = currentFlavors.getDouble("sweet"); double bitterRating = currentFlavors.getDouble("bitter"); double meatyRating = currentFlavors.getDouble("meaty"); double piguantRating = currentFlavors.getDouble("piquant"); r.flavors.setSalty(saltyRating); r.flavors.setSour(sourRating); r.flavors.setSweet(sweetRating); r.flavors.setBitter(bitterRating); r.flavors.setMeaty(meatyRating); r.flavors.setPiquant(piguantRating); } if (currentRecipe.get(f) == null) { r.flavors = null; } if (currentRecipe.get(f) == null) r.flavors = null; } double rate = currentRecipe.getInt("rating"); r.setRating(rate); list.matches.add(i, r); } return list; }
From source file:com.currencyconverter.model.WebService.java
public Double getDollarValue(String name) throws ClientProtocolException, IOException, JSONException { String request = "http://rate-exchange.appspot.com/currency?from=USD&to=" + name; JSONObject jObj = getJson(request); Double exResult = jObj.getDouble("rate"); return exResult; }
From source file:com.llc.bumpr.sdk.models.Driver.java
/** * Constructor to create Driver from JSON * @param json The json representation of the driver * @throws JSONException exception thrown from invalid json representation *//*from ww w .j av a 2 s .c o m*/ public Driver(JSONObject json) throws JSONException { id = json.getInt("id"); fee = json.getDouble("fee"); String sRating = json.getString("rating"); if (sRating.equals("null")) rating = 0; else rating = Double.parseDouble(sRating); try { position = new Location(json.getDouble("lat"), json.getDouble("lon")); } catch (JSONException e) { Log.i("com.llc.bumpr.sdk", "Lat/Long not passed to driver"); } }
From source file:fr.bde_eseo.eseomega.lacommande.model.LacmdMenu.java
public LacmdMenu(JSONObject obj) throws JSONException { super(obj.getString("name"), obj.getString("idstr"), 0, 1, obj.getDouble("price"), ID_CAT_MENU); // no ingredients, but elements yes // expressions mainElemStr = obj.getString("mainElemStr"); maxMainElem = obj.getInt("nbMainElem"); maxSecoElem = obj.getInt("nbSecoElem"); }