List of usage examples for org.json JSONException getMessage
public String getMessage()
From source file:org.jabsorb.ng.serializer.impl.DateSerializer.java
@Override public Object marshall(final SerializerState state, final Object p, final Object o) throws MarshallException { long time;// www . j a v a 2 s . co m if (o instanceof Date) { time = ((Date) o).getTime(); } else { throw new MarshallException("cannot marshall date using class " + o.getClass()); } final JSONObject obj = new JSONObject(); try { if (ser.getMarshallClassHints()) { obj.put("javaClass", o.getClass().getName()); } obj.put("time", time); } catch (final JSONException e) { throw new MarshallException(e.getMessage(), e); } return obj; }
From source file:org.jabsorb.ng.serializer.impl.DateSerializer.java
@Override public Object unmarshall(final SerializerState state, Class<?> clazz, final Object o) throws UnmarshallException { final JSONObject jso = (JSONObject) o; long time;/*from w w w . j a va2 s. c o m*/ try { time = jso.getLong("time"); } catch (final JSONException e) { throw new UnmarshallException("Could not get the time in date serialiser", e); } if (jso.has("javaClass")) { try { clazz = Class.forName(jso.getString("javaClass")); } catch (final ClassNotFoundException e) { throw new UnmarshallException(e.getMessage(), e); } catch (final JSONException e) { throw new UnmarshallException("Could not find javaClass", e); } } Object returnValue = null; if (Date.class.equals(clazz)) { returnValue = new Date(time); } else if (Timestamp.class.equals(clazz)) { returnValue = new Timestamp(time); } else if (java.sql.Date.class.equals(clazz)) { returnValue = new java.sql.Date(time); } else if (java.sql.Time.class.equals(clazz)) { returnValue = new Time(time); } if (returnValue == null) { throw new UnmarshallException("invalid class " + clazz); } state.setSerialized(o, returnValue); return returnValue; }
From source file:com.android.i18n.addressinput.LocalDataSource.java
@Override public AddressVerificationNodeData get(String key) { String jsonString = DATA.get(key); if (jsonString != null) { JsoMap jso = null;// w w w .j a v a2s .c om try { jso = JsoMap.buildJsoMap(jsonString); } catch (JSONException e) { System.err.println("unable to get: " + e.getMessage()); return null; } if (jso != null) { return createNodeData(jso); } } return null; }
From source file:ti.notificare.NotificareTitaniumAndroidModule.java
/** * Open a notification in a NotificationActivity * @param notificationObject//from w w w .j a v a 2s. com */ @Kroll.method public void openNotification( @Kroll.argument(optional = false, name = "notification") KrollDict notificationObject) { try { JSONObject json = mapToJson(notificationObject); NotificareNotification notification = new NotificareNotification(json); openNotificationActivity(notification); } catch (JSONException e) { Log.e(TAG, "Error opening notification: " + e.getMessage()); } }
From source file:ti.notificare.NotificareTitaniumAndroidModule.java
/** * Transform a JSONObject into a Map/*from w w w . j a v a 2s . c o m*/ * @see NotificareTitaniumAndroidModule#jsonToObject(Object) for mapping details * @param json * @return */ private static KrollDict jsonToMap(JSONObject json) { KrollDict map = new KrollDict(json.length()); for (Iterator<String> iter = json.keys(); iter.hasNext();) { String key = iter.next(); try { Object value = json.get(key); map.put(key, jsonToObject(value)); } catch (JSONException e) { Log.e(TAG, "JSON error: " + e.getMessage()); } } return map; }
From source file:ti.notificare.NotificareTitaniumAndroidModule.java
/** * Transform a JSONArray into an Object[] * @see NotificareTitaniumAndroidModule#jsonToObject(Object) for mapping details * @param json/*ww w. j av a2 s. co m*/ * @return */ private static Object[] jsonToArray(JSONArray json) { List<Object> elements = new ArrayList<Object>(json.length()); for (int i = 0; i < json.length(); i++) { try { Object value = json.get(i); elements.add(jsonToObject(value)); } catch (JSONException e) { Log.e(TAG, "JSON error: " + e.getMessage()); } } return elements.toArray(new Object[json.length()]); }
From source file:ti.notificare.NotificareTitaniumAndroidModule.java
/** * Tries to transform a Map into a JSONObject * Non-String keys or non-mappable values are left out * @param map//w w w . jav a 2 s . co m * @return */ private static JSONObject mapToJson(Map<?, ?> map) { JSONObject json = new JSONObject(); for (Object key : map.keySet()) { if (key instanceof String) { try { json.put((String) key, objectToJson(map.get(key))); } catch (JSONException e) { Log.e(TAG, "JSON error: " + e.getMessage()); } } } return json; }
From source file:com.nit.vicky.multimediacard.activity.MultimediaCardEditorActivity.java
/** * Creates the UI for editor area inside EditorLayout * /*w ww. j a v a 2 s. com*/ * @param note */ private void createEditorUI(IMultimediaEditableNote note) { try { if (mNote == null) { finishCancel(); return; } else { for (int i = 0; i < mNote.getNumberOfFields(); ++i) { IField f = mNote.getField(i); if (f == null) { finishCancel(); return; } } } LinearLayout linearLayout = mEditorLayout; linearLayout.removeAllViews(); for (int i = 0; i < note.getNumberOfFields(); ++i) { createNewViewer(linearLayout, note.getField(i), i); } mModelButton.setText(gtxt(R.string.multimedia_editor_activity_note_type) + " : " + mEditorNote.model().getString("name")); mDeckButton.setText(gtxt(R.string.multimedia_editor_activity_deck) + " : " + mCol.getDecks().get(mCurrentDid).getString("name")); } catch (JSONException e) { Log.e("Multimedia Editor", e.getMessage()); return; } }
From source file:com.nit.vicky.multimediacard.activity.MultimediaCardEditorActivity.java
private Dialog showModelSelectDialog() { StyledDialog dialog = null;//from w ww . j a v a2 s.c om StyledDialog.Builder builder = new StyledDialog.Builder(this); ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>(); // Use this array to know which ID is associated with each // Item(name) final ArrayList<Long> dialogIds = new ArrayList<Long>(); ArrayList<JSONObject> models = mCol.getModels().all(); Collections.sort(models, new JSONNameComparator()); builder.setTitle(R.string.note_type); for (JSONObject m : models) { try { dialogItems.add(m.getString("name")); dialogIds.add(m.getLong("id")); } catch (JSONException e) { Log.e("Multimedia Editor", e.getMessage()); } } // Convert to Array String[] items2 = new String[dialogItems.size()]; dialogItems.toArray(items2); builder.setItems(items2, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { long oldModelId; try { oldModelId = mCol.getModels().current().getLong("id"); } catch (JSONException e) { Log.e("Multimedia Editor", e.getMessage()); return; } long newId = dialogIds.get(item); if (oldModelId != newId) { changeCurrentModel(newId); createEditorUI(mNote); } } }); dialog = builder.create(); return dialog; }
From source file:com.nit.vicky.multimediacard.activity.MultimediaCardEditorActivity.java
private Dialog showDeckSelectDialog() { StyledDialog dialog = null;/*from www . j a v a2s . c o m*/ StyledDialog.Builder builder = new StyledDialog.Builder(this); ArrayList<CharSequence> dialogDeckItems = new ArrayList<CharSequence>(); // Use this array to know which ID is associated with each // Item(name) final ArrayList<Long> dialogDeckIds = new ArrayList<Long>(); ArrayList<JSONObject> decks = mCol.getDecks().all(); Collections.sort(decks, new JSONNameComparator()); builder.setTitle(R.string.deck); for (JSONObject d : decks) { try { if (d.getInt("dyn") == 0) { dialogDeckItems.add(d.getString("name")); dialogDeckIds.add(d.getLong("id")); } } catch (JSONException e) { Log.e("Multimedia Editor", e.getMessage()); } } // Convert to Array String[] items = new String[dialogDeckItems.size()]; dialogDeckItems.toArray(items); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { long newId = dialogDeckIds.get(item); if (mCurrentDid != newId) { if (mAddNote) { try { // TODO: mEditorNote.setDid(newId); mEditorNote.model().put("did", newId); mCol.getModels().setChanged(); } catch (JSONException e) { Log.e("Multimedia Editor", e.getMessage()); } } mCurrentDid = newId; createEditorUI(mNote); } } }); dialog = builder.create(); return dialog; }