List of usage examples for org.json JSONObject getLong
public long getLong(String key) throws JSONException
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;// ww w . j a v a2 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.nit.vicky.multimediacard.activity.MultimediaCardEditorActivity.java
private Dialog showModelSelectDialog() { StyledDialog dialog = null;//w ww . jav a 2 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;//w ww. j a v a2 s.co 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; }
From source file:com.google.android.apps.santatracker.service.LocalApiProcessor.java
private JSONObject parseData(String data) throws JSONException { JSONObject json = new JSONObject(data); // Replace the offset with a hardcoded offset // Set the current time to now if the now timestamp is negative if (json.getLong(FIELD_NOW) < 0L) { json.put(FIELD_NOW, System.currentTimeMillis()); }//from w ww. j av a 2 s. c om // Reset the fingerprint with each request for testing // json.put(FIELD_FINGERPRINT, Long.toString(System.currentTimeMillis())); return json; }
From source file:com.facebook.internal.BundleJSONConverterTests.java
@SmallTest public void testSimpleValues() throws JSONException { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("1st"); arrayList.add("2nd"); arrayList.add("third"); Bundle innerBundle1 = new Bundle(); innerBundle1.putInt("inner", 1); Bundle innerBundle2 = new Bundle(); innerBundle2.putString("inner", "2"); innerBundle2.putStringArray("deep list", new String[] { "7", "8" }); innerBundle1.putBundle("nested bundle", innerBundle2); Bundle b = new Bundle(); b.putBoolean("boolValue", true); b.putInt("intValue", 7); b.putLong("longValue", 5000000000l); b.putDouble("doubleValue", 3.14); b.putString("stringValue", "hello world"); b.putStringArray("stringArrayValue", new String[] { "first", "second" }); b.putStringArrayList("stringArrayListValue", arrayList); b.putBundle("nested", innerBundle1); JSONObject json = BundleJSONConverter.convertToJSON(b); assertNotNull(json);/* w w w.j av a 2s .com*/ assertEquals(true, json.getBoolean("boolValue")); assertEquals(7, json.getInt("intValue")); assertEquals(5000000000l, json.getLong("longValue")); assertEquals(3.14, json.getDouble("doubleValue")); assertEquals("hello world", json.getString("stringValue")); JSONArray jsonArray = json.getJSONArray("stringArrayValue"); assertEquals(2, jsonArray.length()); assertEquals("first", jsonArray.getString(0)); assertEquals("second", jsonArray.getString(1)); jsonArray = json.getJSONArray("stringArrayListValue"); assertEquals(3, jsonArray.length()); assertEquals("1st", jsonArray.getString(0)); assertEquals("2nd", jsonArray.getString(1)); assertEquals("third", jsonArray.getString(2)); JSONObject innerJson = json.getJSONObject("nested"); assertEquals(1, innerJson.getInt("inner")); innerJson = innerJson.getJSONObject("nested bundle"); assertEquals("2", innerJson.getString("inner")); jsonArray = innerJson.getJSONArray("deep list"); assertEquals(2, jsonArray.length()); assertEquals("7", jsonArray.getString(0)); assertEquals("8", jsonArray.getString(1)); Bundle finalBundle = BundleJSONConverter.convertToBundle(json); assertNotNull(finalBundle); assertEquals(true, finalBundle.getBoolean("boolValue")); assertEquals(7, finalBundle.getInt("intValue")); assertEquals(5000000000l, finalBundle.getLong("longValue")); assertEquals(3.14, finalBundle.getDouble("doubleValue")); assertEquals("hello world", finalBundle.getString("stringValue")); List<String> stringList = finalBundle.getStringArrayList("stringArrayValue"); assertEquals(2, stringList.size()); assertEquals("first", stringList.get(0)); assertEquals("second", stringList.get(1)); stringList = finalBundle.getStringArrayList("stringArrayListValue"); assertEquals(3, stringList.size()); assertEquals("1st", stringList.get(0)); assertEquals("2nd", stringList.get(1)); assertEquals("third", stringList.get(2)); Bundle finalInnerBundle = finalBundle.getBundle("nested"); assertEquals(1, finalInnerBundle.getInt("inner")); finalBundle = finalInnerBundle.getBundle("nested bundle"); assertEquals("2", finalBundle.getString("inner")); stringList = finalBundle.getStringArrayList("deep list"); assertEquals(2, stringList.size()); assertEquals("7", stringList.get(0)); assertEquals("8", stringList.get(1)); }
From source file:de.badaix.snapcast.control.RPCRequest.java
void fromJson(JSONObject json) throws JSONException { id = json.getLong("id"); method = json.getString("method"); if (json.has("params")) params = json.getJSONObject("params"); else//from ww w . j ava2s. c o m params = null; }
From source file:de.badaix.snapcast.control.RPCRequest.java
void fromJson(JSONObject json) throws JSONException { id = json.getLong("id"); if (json.has("error")) { error = json.getJSONObject("error"); result = null;//from w w w . j av a2 s . c o m } else if (json.has("result")) { result = json.getJSONObject("result"); error = null; } else throw new JSONException("error and result are null"); }
From source file:com.liferay.alerts.model.PollsQuestion.java
public PollsQuestion(JSONObject question) throws JSONException { _questionId = question.getLong(QUESTION_ID); JSONArray choices = question.getJSONArray(CHOICES); for (int i = 0; i < choices.length(); i++) { _choices.add(new PollsChoice(choices.getJSONObject(i))); }/*from www . j a v a 2s . c o m*/ }
From source file:uk.co.senab.photup.model.Album.java
public Album(JSONObject object, Account account) throws JSONException { super(object, account); mCanUpload = object.getBoolean("can_upload"); mUpdatedTime = object.getLong("updated_time"); }
From source file:com.hichinaschool.flashcards.libanki.Models.java
/** * Load registry from JSON./*from ww w .j av a2s . c om*/ */ public void load(String json) { mChanged = false; mModels = new HashMap<Long, JSONObject>(); try { JSONObject modelarray = new JSONObject(json); JSONArray ids = modelarray.names(); if (ids != null) { for (int i = 0; i < ids.length(); i++) { String id = ids.getString(i); JSONObject o = modelarray.getJSONObject(id); mModels.put(o.getLong("id"), o); } } } catch (JSONException e) { throw new RuntimeException(e); } }