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;
}
}
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 "";
}
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;
}
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;
}
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;
}
Aggregations