Example usage for org.json JSONException getMessage

List of usage examples for org.json JSONException getMessage

Introduction

In this page you can find the example usage for org.json JSONException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.fanfou.app.opensource.api.ApiParser.java

public static List<Search> savedSearches(final String content) throws IOException {
    try {/*w  w  w .  jav a2s .  c o  m*/
        final JSONArray a = new JSONArray(content);
        return ApiParser.savedSearches(a);
    } catch (final JSONException e) {
        if (AppContext.DEBUG) {
            Log.e(ApiParser.TAG, e.getMessage());
        }
    }
    return new ArrayList<Search>();
}

From source file:com.fanfou.app.opensource.api.ApiParser.java

public static ArrayList<Search> trends(final JSONObject o) throws IOException {
    final ArrayList<Search> ts = new ArrayList<Search>();
    try {/* w w w .j a  va 2s .c om*/
        final JSONArray a = o.getJSONArray(ApiParser.TRENDS);
        for (int i = 0; i < a.length(); i++) {
            final Search t = ApiParser.trend(a.getJSONObject(i));
            ts.add(t);
        }
    } catch (final JSONException e) {
        if (AppContext.DEBUG) {
            Log.e(ApiParser.TAG, e.getMessage());
        }
    }

    return ts;
}

From source file:com.fanfou.app.opensource.api.ApiParser.java

public static ArrayList<Search> trends(final String content) throws IOException {
    try {//  www  . jav  a2  s.co m
        final JSONObject o = new JSONObject(content);
        return ApiParser.trends(o);
    } catch (final JSONException e) {
        if (AppContext.DEBUG) {
            Log.e(ApiParser.TAG, e.getMessage());
        }
    }
    return new ArrayList<Search>();
}

From source file:com.soundcloud.playerapi.Http.java

public static JSONObject getJSON(HttpResponse response) throws IOException {
    final String json = getString(response);
    if (json == null || json.length() == 0)
        throw new IOException("JSON response is empty");
    try {/*from ww  w.  j  a  v  a  2 s  .  c o  m*/
        return new JSONObject(json);
    } catch (JSONException e) {
        throw new IOException("could not parse JSON document: " + e.getMessage() + " "
                + (json.length() > 80 ? (json.substring(0, 79) + "...") : json));
    }
}

From source file:com.whalesocks.sunshine.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.//www .j a v a2  s. c  o  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();

        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);
        }

        int inserted = 0;
        // 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);
        }

        //            // Sort order:  Ascending, by date.
        //            String sortOrder = WeatherEntry.COLUMN_DATE + " ASC";
        //            Uri weatherForLocationUri = WeatherEntry.buildWeatherLocationWithStartDate(
        //                    locationSetting, System.currentTimeMillis());
        //
        //            // Students: Uncomment the next lines to display what what you stored in the bulkInsert
        //
        //            Cursor cur = mContext.getContentResolver().query(weatherForLocationUri,
        //                    null, null, null, sortOrder);
        //
        //            cVVector = new Vector<ContentValues>(cur.getCount());
        //            if ( cur.moveToFirst() ) {
        //                do {
        //                    ContentValues cv = new ContentValues();
        //                    DatabaseUtils.cursorRowToContentValues(cur, cv);
        //                    cVVector.add(cv);
        //                } while (cur.moveToNext());
        //            }

        Log.d(LOG_TAG, "FetchWeatherTask Complete. " + cVVector.size() + " Inserted");

        //            String[] resultStrs = convertContentValuesToUXFormat(cVVector);
        //            return resultStrs;

    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
    }
    //        return null;
}

From source file:com.linkedin.platform.errors.LIDeepLinkError.java

@Override
public String toString() {
    try {/*from  ww w.  java2  s.c  om*/
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("errorCode", errorCode.name());
        jsonObject.put("errorMessage", errorMsg);
        return jsonObject.toString(2);
    } catch (JSONException e) {
        Log.d(TAG, e.getMessage());
    }
    return null;
}

From source file:com.ota.updates.json.UploadJSONParser.java

/**
 * Parse the Upload object within the selected JSON string
 *///from w  w  w.ja v  a 2s .  c  o  m
public void parse() {
    try {
        JSONObject jObj = new JSONObject(mJSONString);

        UploadItem uploadItem = new UploadItem();
        uploadItem.setId(jObj.getInt(NAME_ID));
        uploadItem.setDownloads(jObj.getInt(NAME_DOWNLOADS));
        uploadItem.setSize(jObj.getInt(NAME_SIZE));
        uploadItem.setStatus(jObj.getString(NAME_STATUS));
        uploadItem.setMd5(jObj.getString(NAME_MD5));
        uploadItem.setDownloadLink(jObj.getString(NAME_DOWNLOAD_LINK));

        UploadSQLiteHelper helper = new UploadSQLiteHelper(mContext);
        helper.addUpload(uploadItem);
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
    }

}

From source file:com.strato.hidrive.api.bll.free.OrderFreeAccountGateway.java

@Override
protected Request prepareRequest() {
    List<BaseParam<?>> params = new ArrayList<BaseParam<?>>();
    JSONObject json = new JSONObject();
    try {//from   w  ww.java  2 s  .  c  o m
        json.put("data_values", this.orderEntity.getJson());
        json.put("country", this.orderEntity.getCountry());
        json.put("language", this.orderEntity.getLanguage());
        json.put("product_name", "HiDriveFree");
        json.put("product", "freemium");
    } catch (JSONException e) {
        if (e != null && e.getMessage() != null) {
            Log.e(getClass().getSimpleName(), e.getMessage());
        }
    }
    params.add(new Param("postdata", json.toString()));
    return new PostRequest("post_data", params);
}

From source file:com.speedtong.example.ui.account.LoginActivity.java

private void doLoginReuqest(String user_name, String user_pwd) {
    CCPParameters ccpParameters = new CCPParameters();
    ccpParameters.setParamerTagKey("Request");
    ccpParameters.add("secret_key", "a04daaca96294836bef207594a0a4df8");
    ccpParameters.add("user_name", user_name);
    ccpParameters.add("user_pwd", user_pwd);
    AsyncECRequestRunner.requestAsyncForEncrypt(
            "https://sandboxapp.cloopen.com:8883/2013-12-26/General/GetDemoAccounts", ccpParameters, "POST",
            true, new InnerRequestListener() {

                @Override//w  ww  .j a v  a 2  s.co  m
                public void onECRequestException(CCPException arg0) {
                    ECLog4Util.e("TAG", "onECRequestException " + arg0.getMessage());
                    ToastUtil.showMessage(arg0.getMessage());
                    dismissPostingDialog();
                }

                @Override
                public void onComplete(String arg0) {
                    ECLog4Util.e("TAG", "onComplete " + arg0);
                    String json = OrgJosnUtils.xml2json(arg0);
                    if (json != null) {
                        try {
                            JSONObject mJSONObject = (JSONObject) (new JSONObject(json)).get("Response");
                            if ("000000".equals(mJSONObject.get("statusCode"))) {
                                ECLog4Util.e("TAG", "statusCode " + mJSONObject.get("statusCode"));
                                JSONObject app = (JSONObject) mJSONObject.get("Application");
                                JSONArray jarray = new JSONArray(app.get("SubAccount") + "");
                                int length = jarray.length();
                                ArrayList<ECContacts> arraylist = new ArrayList<ECContacts>();
                                for (int i = 0; i < length; i++) {
                                    JSONObject object = (JSONObject) jarray.get(i);
                                    ECContacts bean = new ECContacts(object.getString("voip_account"));
                                    bean.setToken(object.getString("voip_token"));
                                    bean.setSubAccount(object.getString("sub_account"));
                                    bean.setSubToken(object.getString("sub_token"));
                                    arraylist.add((bean));
                                }
                                saveAutoLogin();
                                Intent intent = new Intent(LoginActivity.this, AccountChooseActivity.class);
                                intent.putParcelableArrayListExtra("arraylist", arraylist);
                                intent.putParcelableArrayListExtra("arraylist", arraylist);
                                startActivityForResult(intent, 0xa);
                            } else {
                                ECLog4Util.e("TAG", "statusCode " + mJSONObject.get("statusCode"));
                                String errorMsg = mJSONObject.get("statusCode").toString();
                                if (mJSONObject.has("statusMsg")) {
                                    errorMsg = mJSONObject.get("statusMsg").toString();
                                }
                                ToastUtil.showMessage(errorMsg);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                            ToastUtil.showMessage(e.getMessage());
                        }
                    }

                    dismissPostingDialog();
                }

            });
}

From source file:org.artags.android.app.stackwidget.service.TagService.java

public static List<Tag> getTagList(String url) {
    long start = new Date().getTime();
    Log.i(Constants.LOG_TAG, "Tag Service : begin tag fetching");
    List<Tag> list = new ArrayList<Tag>();
    String jsonflow = HttpUtils.getUrl(url);

    try {/* www .  j  a va  2s.  co  m*/

        JSONTokener tokener = new JSONTokener(jsonflow);
        JSONObject json = (JSONObject) tokener.nextValue();
        JSONArray jsonTags = json.getJSONArray("tags");

        int max = (jsonTags.length() < Constants.MAX_TAGS) ? jsonTags.length() : Constants.MAX_TAGS;
        for (int i = 0; i < max; i++) {
            JSONObject jsonTag = jsonTags.getJSONObject(i);
            Tag tag = new Tag();
            tag.setId(jsonTag.getString("id"));
            tag.setText(jsonTag.getString("title"));
            tag.setThumbnailUrl(jsonTag.getString("imageUrl"));
            tag.setRating(jsonTag.getString("rating"));
            list.add(tag);
        }
    } catch (JSONException e) {
        Log.e(Constants.LOG_TAG, "JSON Parsing Error : " + e.getMessage(), e);
    }
    long end = new Date().getTime();
    Log.i(Constants.LOG_TAG, "Tag Service : " + list.size() + " tags fetched in " + (start - end) + "ms");
    return list;
}