List of usage examples for org.json JSONObject getLong
public long getLong(String key) throws JSONException
From source file:cn.code.notes.gtask.data.TaskList.java
public void setContentByLocalJSON(JSONObject js) { if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) { Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); }//w w w . ja v a2s .c o m try { JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) { String name = folder.getString(NoteColumns.SNIPPET); setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name); } else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER) setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT); else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER) setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_CALL_NOTE); else Log.e(TAG, "invalid system folder"); } else { Log.e(TAG, "error type"); } } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); } }
From source file:com.leanengine.JsonDecode.java
static LeanAccount accountFromJson(JSONObject json) throws LeanException { Long id;/*from w w w. j a v a 2 s .c o m*/ try { id = json.getLong("id"); } catch (JSONException e) { throw new LeanException(LeanError.Type.ServerError, "Malformed reply: Entity JSON missing field 'id'."); } String providerId; try { providerId = json.getString("providerId"); } catch (JSONException e) { throw new LeanException(LeanError.Type.ServerError, "Malformed reply: Entity JSON missing field 'providerId'."); } String nickName; try { nickName = json.getString("nickName"); } catch (JSONException e) { throw new LeanException(LeanError.Type.ServerError, "Malformed reply: Entity JSON missing field 'nickName'."); } String provider; try { provider = json.getString("provider"); } catch (JSONException e) { throw new LeanException(LeanError.Type.ServerError, "Malformed reply: Entity JSON missing field 'provider'."); } JSONObject jsonProviderProperties; Map<String, Object> providerProperties; try { jsonProviderProperties = json.getJSONObject("providerProperties"); providerProperties = accountPropsFromJson(jsonProviderProperties); return new LeanAccount(id, nickName, providerId, provider, providerProperties); } catch (JSONException e) { throw new LeanException(LeanError.Type.ServerError, "Malformed reply: Entity JSON missing field 'providerProperties'."); } }
From source file:com.leanengine.JsonDecode.java
static LeanEntity entityFromJson(JSONObject json) throws LeanException { String kind;/* www . j a v a2 s . c o m*/ try { kind = json.getString("_kind"); } catch (JSONException e) { throw new LeanException(LeanError.Type.ServerError, "Malformed reply: Entity JSON missing field '_kind'."); } Long id; try { id = json.getLong("_id"); } catch (JSONException e) { throw new LeanException(LeanError.Type.ServerError, "Malformed reply: Entity JSON missing field '_id'."); } Long accountId; try { accountId = json.getLong("_account"); } catch (JSONException e) { throw new LeanException(LeanError.Type.ServerError, "Malformed reply: Entity JSON missing field '_account'."); } LeanEntity entity = new LeanEntity(kind, id, accountId); try { entity.properties = entityPropertiesFromJson(json); } catch (JSONException e) { throw new LeanException(LeanError.Type.ServerError, "Malformed reply: " + e); } return entity; }
From source file:com.leanengine.JsonDecode.java
private static long getLongFromValueNode(String fieldName, JSONObject node) throws LeanException { try {/* w w w . ja va2 s. co m*/ return node.getLong(fieldName); } catch (JSONException e) { throw new LeanException(LeanError.Type.ServerError, "Malformed reply: Missing '" + fieldName + "' field."); } }
From source file:cn.code.notes.gtask.data.SqlConn.java
public void setContent(JSONObject js) throws JSONException { String dataGUID = js.has(ConnectColumns.NOTE_GUID) ? js.getString(ConnectColumns.NOTE_GUID) : ""; if (mIsCreate || mGuid.equals(dataGUID)) mDiffDataValues.put(ConnectColumns.NOTE_GUID, dataGUID); mGuid = dataGUID;/*from w w w . ja v a 2 s .com*/ long dataId = js.has(ConnectColumns.NOTE_ID) ? js.getLong(ConnectColumns.NOTE_ID) : INVALID_ID; if (mIsCreate || mId != dataId) { mDiffDataValues.put(ConnectColumns.NOTE_ID, dataId); } mId = dataId; String dataMD5 = js.has(ConnectColumns.NOTE_DATA_MD5) ? js.getString(ConnectColumns.NOTE_DATA_MD5) : ""; if (mIsCreate || mDataMD5.equals(dataMD5)) mDiffDataValues.put(ConnectColumns.NOTE_GUID, dataMD5); mGuid = dataMD5; }
From source file:com.facebook.config.LongExtractor.java
@Override public Long extract(String key, JSONObject jsonObject) throws JSONException { return jsonObject.getLong(key); }
From source file:fr.immotronic.ubikit.pems.enocean.impl.item.data.EEP060001DataImpl.java
public static EEP060001DataImpl constructDataFromRecord(JSONObject lastKnownData) { if (lastKnownData == null) return new EEP060001DataImpl(ContactState.UNKNOWN, null); try {//w w w .j av a 2s . c o m ContactState contactState = ContactState.valueOf(lastKnownData.getString("contactState")); Date date = new Date(lastKnownData.getLong("date")); return new EEP060001DataImpl(contactState, date); } catch (JSONException e) { Logger.error(LC.gi(), null, "constructDataFromRecord(): An exception while building a sensorData from a JSONObject SHOULD never happen. Check the code !", e); return new EEP060001DataImpl(ContactState.UNKNOWN, null); } }
From source file:com.foxykeep.datadroidpoc.data.factory.PhoneListFactory.java
public static ArrayList<Phone> parseResult(String wsResponse) throws DataException { ArrayList<Phone> phoneList = new ArrayList<Phone>(); try {// w w w. j a va 2 s. c o m JSONObject parser = new JSONObject(wsResponse); JSONObject jsonRoot = parser.getJSONObject(JSONTag.CRUD_PHONE_LIST_ELEM_PHONES); JSONArray jsonPhoneArray = jsonRoot.getJSONArray(JSONTag.CRUD_PHONE_LIST_ELEM_PHONE); int size = jsonPhoneArray.length(); for (int i = 0; i < size; i++) { JSONObject jsonPhone = jsonPhoneArray.getJSONObject(i); Phone phone = new Phone(); phone.serverId = jsonPhone.getLong(JSONTag.CRUD_PHONE_LIST_ELEM_ID); phone.name = jsonPhone.getString(JSONTag.CRUD_PHONE_LIST_ELEM_NAME); phone.manufacturer = jsonPhone.getString(JSONTag.CRUD_PHONE_LIST_ELEM_MANUFACTURER); phone.androidVersion = jsonPhone.getString(JSONTag.CRUD_PHONE_LIST_ELEM_ANDROID_VERSION); phone.screenSize = jsonPhone.getDouble(JSONTag.CRUD_PHONE_LIST_ELEM_SCREEN_SIZE); phone.price = jsonPhone.getInt(JSONTag.CRUD_PHONE_LIST_ELEM_PRICE); phoneList.add(phone); } } catch (JSONException e) { Log.e(TAG, "JSONException", e); throw new DataException(e); } return phoneList; }
From source file:com.nextgis.firereporter.ScanexNotificationItem.java
public ScanexNotificationItem(Context c, JSONObject object) { Prepare(c);//from w w w . ja v a 2 s .co m try { this.nID = object.getLong("id"); this.dt = new Date(object.getLong("date")); this.X = object.getDouble("X"); this.Y = object.getDouble("Y"); this.nConfidence = object.getInt("confidence"); this.nPower = object.getInt("power"); this.sURL1 = object.getString("URL1"); this.sURL2 = object.getString("URL2"); this.sType = object.getString("type"); this.sPlace = object.getString("place"); this.sMap = object.getString("map"); this.nIconId = object.getInt("iconId"); this.mbWatched = object.getBoolean("watched"); } catch (JSONException e) { SendError(e.getLocalizedMessage()); } }
From source file:com.textuality.lifesaver.Columns.java
private static void j2cvLong(JSONObject j, ContentValues cv, String key) { try {//from w ww . ja v a 2s .com long v = j.getLong(key); cv.put(key, v); } catch (JSONException e) { } }