Search in sources :

Example 56 with JSONException

use of org.json.JSONException in project weiciyuan by qii.

the class BaiduGeoCoderDao method get.

public String get() throws WeiboException {
    final String url = String.format(URLHelper.BAIDU_GEO_CODER_MAP, lat, long_fix);
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, null);
    try {
        final JSONObject json = new JSONObject(jsonData);
        final JSONObject result = json.getJSONObject("result");
        final String formatAddress = result.optString("formatted_address", null);
        return formatAddress;
    } catch (JSONException exception) {
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 57 with JSONException

use of org.json.JSONException in project weiciyuan by qii.

the class LocationInfoDao method getInfo.

public String getInfo() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("language", "zh-CN");
    map.put("sensor", "false");
    map.put("latlng", getLatlng());
    String url = URLHelper.GOOGLELOCATION;
    String jsonData = null;
    try {
        jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, map);
    } catch (WeiboException e) {
        AppLogger.e(e.getMessage());
    }
    try {
        JSONObject jsonObject = new JSONObject(jsonData);
        JSONArray results = jsonObject.optJSONArray("results");
        JSONObject jsonObject1 = results.getJSONObject(0);
        String formatAddress = jsonObject1.optString("formatted_address");
        int index = formatAddress.indexOf(" ");
        if (index > 0) {
            String location = formatAddress.substring(0, index);
            return location;
        } else {
            return formatAddress;
        }
    } catch (JSONException e) {
        AppLogger.e(e.getMessage());
    }
    return "";
}
Also used : WeiboException(org.qii.weiciyuan.support.error.WeiboException) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 58 with JSONException

use of org.json.JSONException in project weiciyuan by qii.

the class OAuthDao method getOAuthUserInfo.

public UserBean getOAuthUserInfo() throws WeiboException {
    String uidJson = getOAuthUserUIDJsonData();
    String uid = "";
    try {
        JSONObject jsonObject = new JSONObject(uidJson);
        uid = jsonObject.optString("uid");
    } catch (JSONException e) {
        AppLogger.e(e.getMessage());
    }
    Map<String, String> map = new HashMap<String, String>();
    map.put("uid", uid);
    map.put("access_token", access_token);
    String url = URLHelper.USER_SHOW;
    String result = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, map);
    Gson gson = new Gson();
    UserBean user = new UserBean();
    try {
        user = gson.fromJson(result, UserBean.class);
    } catch (JsonSyntaxException e) {
        AppLogger.e(result);
    }
    return user;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) JSONObject(org.json.JSONObject) UserBean(org.qii.weiciyuan.bean.UserBean) HashMap(java.util.HashMap) JSONException(org.json.JSONException) Gson(com.google.gson.Gson)

Example 59 with JSONException

use of org.json.JSONException in project weiciyuan by qii.

the class MapDao method getMap.

public Bitmap getMap() throws WeiboException {
    String url = URLHelper.STATIC_MAP;
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    String coordinates = String.valueOf(lat) + "," + String.valueOf(lan);
    map.put("center_coordinate", coordinates);
    map.put("zoom", "14");
    map.put("size", "600x380");
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, map);
    String mapUrl = "";
    try {
        JSONObject jsonObject = new JSONObject(jsonData);
        JSONArray array = jsonObject.optJSONArray("map");
        jsonObject = array.getJSONObject(0);
        mapUrl = jsonObject.getString("image_url");
    } catch (JSONException e) {
    }
    if (TextUtils.isEmpty(mapUrl)) {
        return null;
    }
    String filePath = FileManager.getFilePathFromUrl(mapUrl, FileLocationMethod.map);
    boolean downloaded = TaskCache.waitForPictureDownload(mapUrl, null, filePath, FileLocationMethod.map);
    if (!downloaded) {
        return null;
    }
    Bitmap bitmap = ImageUtility.readNormalPic(FileManager.getFilePathFromUrl(mapUrl, FileLocationMethod.map), -1, -1);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 60 with JSONException

use of org.json.JSONException in project weiciyuan by qii.

the class TopicDao method follow.

public boolean follow(String trend_name) throws WeiboException {
    String url = URLHelper.TOPIC_FOLLOW;
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    map.put("trend_name", trend_name);
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Post, url, map);
    try {
        JSONObject jsonObject = new JSONObject(jsonData);
        Integer id = jsonObject.optInt("topicid", -1);
        if (id > 0) {
            return true;
        } else {
            return false;
        }
    } catch (JSONException e) {
    }
    return false;
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) JSONException(org.json.JSONException)

Aggregations

JSONException (org.json.JSONException)1904 JSONObject (org.json.JSONObject)1422 JSONArray (org.json.JSONArray)638 IOException (java.io.IOException)338 ArrayList (java.util.ArrayList)211 HashMap (java.util.HashMap)145 Test (org.junit.Test)128 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)98 File (java.io.File)77 Bundle (android.os.Bundle)75 VolleyError (com.android.volley.VolleyError)67 Intent (android.content.Intent)63 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)62 Response (com.android.volley.Response)59 URL (java.net.URL)57 Map (java.util.Map)48 TextView (android.widget.TextView)46 View (android.view.View)45 RandomString (edu.umass.cs.gnscommon.utils.RandomString)44 MalformedURLException (java.net.MalformedURLException)44