use of org.json.JSONException in project android-maps-utils by googlemaps.
the class GeoJsonParser method parseFeatureCollection.
/**
* Parses the array of GeoJSON features in a given GeoJSON feature collection. Also parses the
* bounding box member of the feature collection if it exists.
*
* @param geoJsonFeatureCollection feature collection to parse
* @return array of GeoJsonFeature objects
*/
private ArrayList<GeoJsonFeature> parseFeatureCollection(JSONObject geoJsonFeatureCollection) {
JSONArray geoJsonFeatures;
ArrayList<GeoJsonFeature> features = new ArrayList<GeoJsonFeature>();
try {
geoJsonFeatures = geoJsonFeatureCollection.getJSONArray(FEATURE_COLLECTION_ARRAY);
if (geoJsonFeatureCollection.has(BOUNDING_BOX)) {
mBoundingBox = parseBoundingBox(geoJsonFeatureCollection.getJSONArray(BOUNDING_BOX));
}
} catch (JSONException e) {
Log.w(LOG_TAG, "Feature Collection could not be created.");
return features;
}
for (int i = 0; i < geoJsonFeatures.length(); i++) {
try {
JSONObject feature = geoJsonFeatures.getJSONObject(i);
if (feature.getString("type").equals(FEATURE)) {
GeoJsonFeature parsedFeature = parseFeature(feature);
if (parsedFeature != null) {
// Don't add null features
features.add(parsedFeature);
} else {
Log.w(LOG_TAG, "Index of Feature in Feature Collection that could not be created: " + i);
}
}
} catch (JSONException e) {
Log.w(LOG_TAG, "Index of Feature in Feature Collection that could not be created: " + i);
}
}
return features;
}
use of org.json.JSONException in project OkVolley by googolmo.
the class BaseRequest method parseNetworkResponse.
@Override
protected //解析返回的数据
Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
try {
byte[] data = response.data;
String json = new String(data, HttpHeaderParser.parseCharset(response.headers));
if (VolleyLog.DEBUG) {
VolleyLog.d("response:%s", json);
}
return Response.success(new JSONObject(json), HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException e) {
return Response.error(new ParseError(e));
}
}
use of org.json.JSONException in project android-maps-utils by googlemaps.
the class GeoJsonDemoActivity method retrieveFileFromResource.
private void retrieveFileFromResource() {
try {
GeoJsonLayer layer = new GeoJsonLayer(getMap(), R.raw.earthquakes_with_usa, this);
addGeoJsonLayerToMap(layer);
} catch (IOException e) {
Log.e(mLogTag, "GeoJSON file could not be read");
} catch (JSONException e) {
Log.e(mLogTag, "GeoJSON file could not be converted to a JSONObject");
}
}
use of org.json.JSONException in project android-maps-utils by googlemaps.
the class HeatmapsDemoActivity method startDemo.
@Override
protected void startDemo() {
getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-25, 143), 4));
// Set up the spinner/dropdown list
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.heatmaps_datasets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new SpinnerActivity());
try {
mLists.put(getString(R.string.police_stations), new DataSet(readItems(R.raw.police), getString(R.string.police_stations_url)));
mLists.put(getString(R.string.medicare), new DataSet(readItems(R.raw.medicare), getString(R.string.medicare_url)));
} catch (JSONException e) {
Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
}
// Make the handler deal with the map
// Input: list of WeightedLatLngs, minimum and maximum zoom levels to calculate custom
// intensity from, and the map to draw the heatmap on
// radius, gradient and opacity not specified, so default are used
}
use of org.json.JSONException in project smooth-app-bar-layout by henrytao-me.
the class BaseActivity method requestItemsForPurchase.
private void requestItemsForPurchase(final AsyncCallback<List<PurchaseItem>> callback) {
if (mPurchaseItems != null && mPurchaseItems.size() > 0) {
if (callback != null) {
callback.onSuccess(mPurchaseItems);
}
return;
}
new AsyncTask<IInAppBillingService, Void, AsyncResult<List<PurchaseItem>>>() {
@Override
protected AsyncResult<List<PurchaseItem>> doInBackground(IInAppBillingService... params) {
List<PurchaseItem> result = new ArrayList<>();
Throwable exception = null;
IInAppBillingService billingService = params[0];
if (billingService == null) {
exception = new Exception("Unknow");
} else {
ArrayList<String> skuList = new ArrayList<>(Arrays.asList(DONATE_ITEMS));
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
try {
Bundle skuDetails = billingService.getSkuDetails(3, getPackageName(), "inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
PurchaseItem purchaseItem;
for (String item : responseList) {
purchaseItem = new PurchaseItem(new JSONObject(item));
if (purchaseItem.isValid()) {
result.add(purchaseItem);
}
}
}
} catch (RemoteException e) {
e.printStackTrace();
exception = e;
} catch (JSONException e) {
e.printStackTrace();
exception = e;
}
}
return new AsyncResult<>(result, exception);
}
@Override
protected void onPostExecute(AsyncResult<List<PurchaseItem>> result) {
if (!isFinishing() && callback != null) {
Throwable error = result.getError();
if (error == null && (result.getResult() == null || result.getResult().size() == 0)) {
error = new Exception("Unknow");
}
if (error != null) {
callback.onError(error);
} else {
mPurchaseItems = result.getResult();
Collections.sort(mPurchaseItems, new Comparator<PurchaseItem>() {
@Override
public int compare(PurchaseItem lhs, PurchaseItem rhs) {
return (int) ((lhs.getPriceAmountMicros() - rhs.getPriceAmountMicros()) / 1000);
}
});
callback.onSuccess(mPurchaseItems);
}
}
}
}.execute(mBillingService);
}
Aggregations