List of usage examples for org.json JSONException getMessage
public String getMessage()
From source file:com.chess.genesis.net.SyncClient.java
private void sync_recent(final JSONObject json) { try {//from w w w .jav a2 s. c om final JSONArray ids = json.getJSONArray("gameids"); final ExecutorService pool = Executors.newCachedThreadPool(); for (int i = 0, len = ids.length(); i < len; i++) { if (error) return; final NetworkClient nc = new NetworkClient(context, handle); nc.game_status(ids.getString(i)); pool.submit(nc); lock++; } // Save sync time final PrefEdit pref = new PrefEdit(context); pref.putLong(R.array.pf_lastgamesync, json.getLong("time")); pref.commit(); } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.chess.genesis.net.SyncClient.java
private void sync_active(final JSONObject json) { try {//from w ww .ja v a2 s .co m final ArrayList<String> list_need = getNeedList(json.getJSONArray("gameids")); final ExecutorService pool = Executors.newCachedThreadPool(); for (final String item : list_need) { if (error) return; final NetworkClient nc = new NetworkClient(context, handle); nc.game_info(item); pool.submit(nc); lock++; } // don't save time if only syncing active if (syncType == ACTIVE_SYNC) return; // Save sync time final long time = json.getLong("time"); final PrefEdit pref = new PrefEdit(context); pref.putLong(R.array.pf_lastgamesync, time); pref.commit(); } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.chess.genesis.net.SyncClient.java
private void sync_archive(final JSONObject json) { try {//from w w w. j a v a2 s. c om final ArrayList<String> list_need = getNeedList(json.getJSONArray("gameids")); final ExecutorService pool = Executors.newCachedThreadPool(); for (final String item : list_need) { if (error) return; final NetworkClient nc = new NetworkClient(context, handle); nc.game_data(item); pool.submit(nc); lock++; } } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.chess.genesis.net.SyncClient.java
private ArrayList<String> getNeedList(final JSONArray ids) { try {//from ww w . j a v a 2 s. co m final ArrayList<String> list_need = new ArrayList<String>(ids.length()); for (int i = 0, len = ids.length(); i < len; i++) list_need.add(ids.getString(i)); if (syncType == ACTIVE_SYNC || syncType == ARCHIVE_SYNC) return list_need; final GameDataDB db = new GameDataDB(context); final List<String> list = gameType == Enums.ONLINE_GAME ? db.getOnlineGameIds() : db.getArchiveGameIds(); db.close(); final ArrayList<String> list_have = new ArrayList<String>(list.size()); for (final String item : list) list_have.add(item); list_need.removeAll(list_have); return list_need; } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.chess.genesis.net.SyncClient.java
private void saveMsgs(final JSONObject data) { try {//from w ww. ja va 2s .c o m final JSONArray msgs = data.getJSONArray("msglist"); final long time = data.getLong("time"); final GameDataDB db = new GameDataDB(context); for (int i = 0, len = msgs.length(); i < len; i++) { final JSONObject item = msgs.getJSONObject(i); db.insertMsg(item); } db.close(); // Save sync time final PrefEdit pref = new PrefEdit(context); pref.putLong(R.array.pf_lastmsgsync, time); pref.commit(); } catch (final JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:org.apache.cordova.contacts.ContactAccessor.java
/** * Create a hash map of what data needs to be populated in the Contact object * @param fields the list of fields to populate * @return the hash map of required data *//*from w ww .ja v a 2 s . c o m*/ protected HashMap<String, Boolean> buildPopulationSet(JSONObject options) { HashMap<String, Boolean> map = new HashMap<String, Boolean>(); String key; try { JSONArray desiredFields = null; if (options != null && options.has("desiredFields")) { desiredFields = options.getJSONArray("desiredFields"); } if (desiredFields == null || desiredFields.length() == 0) { map.put("displayName", true); map.put("name", true); map.put("nickname", true); map.put("phoneNumbers", true); map.put("emails", true); map.put("addresses", true); map.put("ims", true); map.put("organizations", true); map.put("birthday", true); map.put("note", true); map.put("urls", true); map.put("photos", true); map.put("categories", true); } else { for (int i = 0; i < desiredFields.length(); i++) { key = desiredFields.getString(i); if (key.startsWith("displayName")) { map.put("displayName", true); } else if (key.startsWith("name")) { map.put("displayName", true); map.put("name", true); } else if (key.startsWith("nickname")) { map.put("nickname", true); } else if (key.startsWith("phoneNumbers")) { map.put("phoneNumbers", true); } else if (key.startsWith("emails")) { map.put("emails", true); } else if (key.startsWith("addresses")) { map.put("addresses", true); } else if (key.startsWith("ims")) { map.put("ims", true); } else if (key.startsWith("organizations")) { map.put("organizations", true); } else if (key.startsWith("birthday")) { map.put("birthday", true); } else if (key.startsWith("note")) { map.put("note", true); } else if (key.startsWith("urls")) { map.put("urls", true); } else if (key.startsWith("photos")) { map.put("photos", true); } else if (key.startsWith("categories")) { map.put("categories", true); } } } } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } return map; }
From source file:org.apache.cordova.contacts.ContactAccessor.java
/** * Convenience method to get a string from a JSON object. Saves a * lot of try/catch writing./*from www . j a va2s . co m*/ * If the property is not found in the object null will be returned. * * @param obj contact object to search * @param property to be looked up * @return The value of the property */ protected String getJsonString(JSONObject obj, String property) { String value = null; try { if (obj != null) { value = obj.getString(property); if (value.equals("null")) { Log.d(LOG_TAG, property + " is string called 'null'"); value = null; } } } catch (JSONException e) { Log.d(LOG_TAG, "Could not get = " + e.getMessage()); } return value; }
From source file:com.phonegap.ContactAccessor.java
/** * Create a hash map of what data needs to be populated in the Contact object * @param fields the list of fields to populate * @return the hash map of required data *//*from w w w . j av a 2 s . c om*/ protected HashMap<String, Boolean> buildPopulationSet(JSONArray fields) { HashMap<String, Boolean> map = new HashMap<String, Boolean>(); String key; try { for (int i = 0; i < fields.length(); i++) { key = fields.getString(i); if (key.startsWith("displayName")) { map.put("displayName", true); } else if (key.startsWith("name")) { map.put("name", true); } else if (key.startsWith("nickname")) { map.put("nickname", true); } else if (key.startsWith("phoneNumbers")) { map.put("phoneNumbers", true); } else if (key.startsWith("emails")) { map.put("emails", true); } else if (key.startsWith("addresses")) { map.put("addresses", true); } else if (key.startsWith("ims")) { map.put("ims", true); } else if (key.startsWith("organizations")) { map.put("organizations", true); } else if (key.startsWith("birthday")) { map.put("birthday", true); } else if (key.startsWith("anniversary")) { map.put("anniversary", true); } else if (key.startsWith("note")) { map.put("note", true); } else if (key.startsWith("relationships")) { map.put("relationships", true); } else if (key.startsWith("urls")) { map.put("urls", true); } else if (key.startsWith("photos")) { map.put("photos", true); } } } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } return map; }
From source file:com.phonegap.ContactAccessor.java
/** * Convenience method to get a string from a JSON object. Saves a * lot of try/catch writing./*from w w w. j a v a 2 s. c om*/ * If the property is not found in the object null will be returned. * * @param obj contact object to search * @param property to be looked up * @return The value of the property */ protected String getJsonString(JSONObject obj, String property) { String value = null; try { value = obj.getString(property); if (value.equals("null")) { Log.d(LOG_TAG, property + " is string called 'null'"); value = null; } } catch (JSONException e) { Log.d(LOG_TAG, "Could not get = " + e.getMessage()); } return value; }
From source file:es.deustotech.piramide.utils.net.JSONParser.java
public static Vector<Point> parseFromUrl(HttpEntity httpEntity) { if (httpEntity != null) { InputStream inStream;// w w w.j a v a 2 s . c o m try { inStream = httpEntity.getContent(); result = convertStreamToString(inStream); points = new Vector<Point>(); final JSONObject jsonObj = new JSONObject(result); final JSONObject result = jsonObj.getJSONObject(Constants.JSON_RESPONSE_DATA); //show 8 results for (int i = 0; i < 8; i++) { final JSONObject resultAux = (JSONObject) result.getJSONArray(Constants.JSON_RESULTS).get(i); // final JSONObject phoneAux = (JSONObject) resultAux.getJSONArray(Constants.JSON_PHONE_NUMBERS).get(0); final Point point = new Point(resultAux.getString(Constants.JSON_TITLE), resultAux.getString(Constants.JSON_STREET), resultAux.getString(Constants.JSON_LAT), resultAux.getString(Constants.JSON_LNG) /*new PhoneNumbers(phoneAux.getString(Constants.JSON_TYPE), phoneAux.getString(Constants.JSON_NUMBER)), resultAux.getString(Constants.JSON_CITY), resultAux.getString(Constants.JSON_TITLE), resultAux.getString(Constants.JSON_REGION), resultAux.getString(Constants.JSON_TITLE_NO_FORMATTING), resultAux.getString(Constants.JSON_STREET), resultAux.getJSONArray(Constants.JSON_ADDRESS_LINES).getString(0), resultAux.getString(Constants.JSON_COUNTRY), resultAux.getString(Constants.JSON_LAT), resultAux.getString(Constants.JSON_LNG), resultAux.getString(Constants.JSON_TO_HERE), resultAux.getString(Constants.JSON_FROM_HERE)*/); points.add(point); } // final JSONObject phoneAux = (JSONObject) result.getJSONArray(Constants.JSON_PHONE_NUMBERS).get(0); /* Log.i(Constants.TAG, "<jsonobject>\n" + jsonObj.toString() + "\n</jsonobject>"); final JSONArray nameArray = jsonObj.names(); final JSONArray valArray = jsonObj.toJSONArray(nameArray); for(int i=0; i<valArray.length(); i++) { Log.e(Constants.TAG, "<jsonname" + i + ">\n" + nameArray.getString(i) + "\n</jsonname" + i + ">\n" + "<jsonvalue" + i + ">\n" + valArray.getString(i) + "\n</jsonvalue" + i + ">"); } jsonObj.put(Constants.SAMPLE_KEY, Constants.SAMPLE_VALUE); Log.i(Constants.TAG, "<jsonobject>\n" + jsonObj.toString() + "\n</jsonobject>"); */ inStream.close(); } catch (IllegalStateException ise) { Log.d(Constants.TAG, ise.getMessage()); } catch (IOException ioe) { Log.d(Constants.TAG, ioe.getMessage()); } catch (JSONException je) { Log.d(Constants.TAG, je.getMessage()); } } // If the response does not enclose an entity, there is no need // to worry about connection release return points; }