Android Open Source - anti-piracy-android-app Asam Json Parser






From Project

Back to project page anti-piracy-android-app.

License

The source code is released under:

Apache License

If you think the Android project anti-piracy-android-app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package mil.nga.giat.asam.model;
//from www . ja  va2 s  .c  om
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import mil.nga.giat.asam.util.AsamLog;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


public class AsamJsonParser {

    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
    
    public List<AsamBean> parseJson(String json) throws Exception {
        List<AsamBean> asams = new ArrayList<AsamBean>();
        JSONArray array = new JSONArray(json);
        for (int i = 0; i < array.length(); i++) {
            JSONObject object = array.getJSONObject(i);
            AsamBean asam = new AsamBean();
            asam.setReferenceNumber(extractString("Reference", object));
            asam.setAggressor(extractString("Aggressor", object));
            asam.setVictim(extractString("Victim", object));
            asam.setDescription(extractString("Description", object));
            asam.setGeographicalSubregion(extractString("Subregion", object));
            asam.setLatitude(extractDouble("lat", object));
            asam.setLongitude(extractDouble("lng", object));
            asam.setOccurrenceDate(extractDate("Date", object));
            asams.add(asam);
        }
        return asams;
    }
    
    private String extractString(String key, JSONObject object) {
        String value = null;
        if (object.has(key) && !object.isNull(key)) {
            try {
                value = object.getString(key).trim().replaceAll("\\+s", " ");
            }
            catch (JSONException caught) {
                AsamLog.e(AsamJsonParser.class.getName() + ":Error extracting " + key, caught);
            }
        }
        return value;
    }
    
    private Double extractDouble(String key, JSONObject object) {
        Double value = null;
        if (object.has(key) && !object.isNull(key)) {
            try {
                value = object.getDouble(key);
            }
            catch (JSONException caught) {
                AsamLog.e(AsamJsonParser.class.getName() + ":Error extracting " + key, caught);
            }
        }
        return value;
    }
    
    private Date extractDate(String key, JSONObject object) {
        Date value = null;
        if (object.has(key) && !object.isNull(key)) {
            try {
                value = DATE_FORMAT.parse(object.getString(key));
            }
            catch (Exception caught) {
                AsamLog.e(AsamJsonParser.class.getName() + ":Error extracting " + key, caught);
            }
        }
        return value;
    }
}




Java Source Code List

mil.nga.giat.asam.AsamListActivity.java
mil.nga.giat.asam.AsamListFragment.java
mil.nga.giat.asam.AsamListReportTabletActivity.java
mil.nga.giat.asam.AsamReportActivity.java
mil.nga.giat.asam.AsamReportFragment.java
mil.nga.giat.asam.Asam.java
mil.nga.giat.asam.DisclaimerActivity.java
mil.nga.giat.asam.DisclaimerDialogFragment.java
mil.nga.giat.asam.InfoActivity.java
mil.nga.giat.asam.InfoDialogFragment.java
mil.nga.giat.asam.InfoFragment.java
mil.nga.giat.asam.LaunchScreenActivity.java
mil.nga.giat.asam.LegalActivity.java
mil.nga.giat.asam.LegalDetailsActivity.java
mil.nga.giat.asam.LegalDetailsFragment.java
mil.nga.giat.asam.LegalFragment.java
mil.nga.giat.asam.LegalTabletActivity.java
mil.nga.giat.asam.MainActivity.java
mil.nga.giat.asam.PreferencesActivity.java
mil.nga.giat.asam.PreferencesDialogFragment.java
mil.nga.giat.asam.SortAsamListDialogFragment.java
mil.nga.giat.asam.TextQueryActivity.java
mil.nga.giat.asam.TextQueryDialogFragment.java
mil.nga.giat.asam.connectivity.NetworkChangeReceiver.java
mil.nga.giat.asam.connectivity.OfflineBannerFragment.java
mil.nga.giat.asam.db.AsamDbHelper.java
mil.nga.giat.asam.jackson.deserializer.Deserializer.java
mil.nga.giat.asam.jackson.deserializer.FeatureDeserializer.java
mil.nga.giat.asam.jackson.deserializer.GeometryDeserializer.java
mil.nga.giat.asam.map.AllAsamsMapActivity.java
mil.nga.giat.asam.map.AllAsamsMapTabletActivity.java
mil.nga.giat.asam.map.BackgroundTileProvider.java
mil.nga.giat.asam.map.OfflineMap.java
mil.nga.giat.asam.map.SingleAsamMapActivity.java
mil.nga.giat.asam.map.SubregionMapActivity.java
mil.nga.giat.asam.model.AsamBean.java
mil.nga.giat.asam.model.AsamJsonParser.java
mil.nga.giat.asam.model.AsamMapClusterBean.java
mil.nga.giat.asam.model.LegalBean.java
mil.nga.giat.asam.model.SubregionBean.java
mil.nga.giat.asam.model.SubregionTextParser.java
mil.nga.giat.asam.model.TextQueryParametersBean.java
mil.nga.giat.asam.net.AsamWebService.java
mil.nga.giat.asam.util.AsamConstants.java
mil.nga.giat.asam.util.AsamListContainer.java
mil.nga.giat.asam.util.AsamLog.java
mil.nga.giat.asam.util.AsamUtils.java
mil.nga.giat.asam.util.CurrentSubregionHelper.java
mil.nga.giat.asam.util.ManifestMetaData.java
mil.nga.giat.asam.util.SyncTime.java
mil.nga.giat.asam.widget.AsamArrayAdapter.java