List of usage examples for org.json JSONObject keys
public Iterator keys()
From source file:org.jabsorb.ng.serializer.impl.RawJSONObjectSerializer.java
@Override public Object marshall(final SerializerState state, final Object p, final Object o) throws MarshallException { // reprocess the raw json in order to fixup circular references and // duplicates final JSONObject jsonIn = (JSONObject) o; final JSONObject jsonOut = new JSONObject(); String key = null;// ww w . j av a 2 s. c o m try { final Iterator<?> i = jsonIn.keys(); while (i.hasNext()) { key = (String) i.next(); final Object j = ser.marshall(state, o, jsonIn.get(key), key); // omit the object entirely if it's a circular reference or // duplicate // it will be regenerated in the fixups phase if (JSONSerializer.CIRC_REF_OR_DUPLICATE != j) { jsonOut.put(key, j); } } } catch (final MarshallException e) { throw new MarshallException("JSONObject key " + key + " " + e.getMessage(), e); } catch (final JSONException e) { throw new MarshallException("JSONObject key " + key + " " + e.getMessage(), e); } return jsonOut; }
From source file:com.norman0406.slimgress.API.Knobs.WeaponRangeKnobs.java
public WeaponRangeKnobs(JSONObject json) throws JSONException { super(json);// ww w . j a va 2s. c o m JSONObject ultraStrikeDamageRangeMap = json.getJSONObject("ultraStrikeDamageRangeMap"); mUltraStrikeDamageRangeMap = new SparseIntArray(); Iterator<?> it1 = ultraStrikeDamageRangeMap.keys(); while (it1.hasNext()) { String strKey = (String) it1.next(); Integer key = Integer.parseInt(strKey); mUltraStrikeDamageRangeMap.put(key, ultraStrikeDamageRangeMap.getInt(strKey)); } JSONObject xmpDamageRangeMap = json.getJSONObject("xmpDamageRangeMap"); mXmpDamageRangeMap = new SparseIntArray(); Iterator<?> it2 = xmpDamageRangeMap.keys(); while (it2.hasNext()) { String strKey = (String) it2.next(); Integer key = Integer.parseInt(strKey); mXmpDamageRangeMap.put(key, xmpDamageRangeMap.getInt(strKey)); } }
From source file:com.jsonstore.api.JSONStoreQueryPart.java
/** * @exclude/*from w ww. j a va 2 s . c o m*/ */ private void parseTuple(JSONObject tuple, QueryPartOperation operation, List<JSONStoreQueryPartItem> result) throws JSONStoreFindException { //Enforce restrictions: if (tuple.length() == 0) { throw new JSONStoreFindException( "Cannot parse query content part. An internal error occurred parsing part tuple", null); } Iterator<String> tupleIterator = tuple.keys(); while (tupleIterator.hasNext()) { String key = tupleIterator.next(); Object val; try { val = tuple.get(key); } catch (JSONException e) { throw new JSONStoreFindException( "Cannot parse query content query part. An internal error occurred parsing part tuple", e); } JSONStoreQueryPartItem part = parseItem(key, false, operation, val); if (part != null) result.add(part); } }
From source file:com.jsonstore.api.JSONStoreQueryPart.java
/** * @exclude/*ww w. j av a 2s .c o m*/ */ private void parse(JSONObject incoming, QueryPartOperation operation, List<JSONStoreQueryPartItem> results) throws JSONStoreFindException { if (incoming == null || operation == null || results == null) return; Iterator<String> incomingKeyIterator = incoming.keys(); while (incomingKeyIterator.hasNext()) { String currentIncomingKey = incomingKeyIterator.next(); if (operation.queryStringMatches(currentIncomingKey)) { JSONArray operationArray = null; try { operationArray = incoming.getJSONArray(currentIncomingKey); } catch (JSONException e) { throw new JSONStoreFindException("Cannot parse query content part. " + currentIncomingKey + " query must be a json array.", e); } for (int i = 0; i < operationArray.length(); i++) { JSONObject operationTuple = null; try { operationTuple = operationArray.getJSONObject(i); } catch (JSONException e) { throw new JSONStoreFindException("Cannot parse query content part. " + currentIncomingKey + " query must contain a JSON object at index " + i, e); } parseTuple(operationTuple, operation, results); } } } }
From source file:com.hotstar.player.adplayer.feeds.ReferencePlayerFeedItemAdapter.java
/** * Gets field value from JSON object given field name * /*from ww w.ja v a2 s. c om*/ * @param jsonObject * - JSON object to search in * @param fieldName * - field name to be searched for * @return String - field value or null if field name does not exist or * field value is empty */ protected String getString(JSONObject jsonObject, String fieldName) { /* try { if (jsonObject.has(fieldName) && !jsonObject.isNull(fieldName)) { return jsonObject.getString(fieldName); } } catch (JSONException e) { AdVideoApplication.logger.e(LOG_TAG + "::getString", "Error getting field from JSON: " + e.getMessage()); } */ try { Iterator<String> iter = jsonObject.keys(); while (iter.hasNext()) { String key1 = iter.next(); if (key1.equalsIgnoreCase(fieldName)) { if (!jsonObject.isNull(key1)) return jsonObject.getString(key1); else return null; } } } catch (JSONException e) { AdVideoApplication.logger.e(LOG_TAG + "::getString", "Error getting field from JSON: " + e.getMessage()); } return null; }
From source file:com.ademsha.appnotifico.NotificationDataHelper.java
public static String getStatusBarNotificationAttribute(JSONObject statusBarNotification, String attributeKey) { String group = "unknown"; for (Iterator<String> iterator = statusBarNotification.keys(); iterator.hasNext();) { String key = iterator.next(); if (key != null && key.equals(attributeKey)) try { return String.valueOf(statusBarNotification.get(key)).replace("null", ""); } catch (JSONException e) { e.printStackTrace();/*from w w w.ja v a 2s.c o m*/ } } return group; }
From source file:org.onebusaway.gtfs_transformer.factory.TransformFactory.java
private void setObjectPropertiesFromJsonUsingCsvFields(Object object, JSONObject json, String line) throws JSONException, TransformSpecificationMissingArgumentException { EntitySchemaFactory entitySchemaFactory = _transformer.getReader().getEntitySchemaFactory(); EntitySchema schema = entitySchemaFactory.getSchema(object.getClass()); BeanWrapper wrapped = BeanWrapperFactory.wrap(object); Map<String, Object> values = new HashMap<String, Object>(); for (Iterator<?> it = json.keys(); it.hasNext();) { String key = (String) it.next(); Object v = json.get(key); if (v instanceof JSONArray) { JSONArray array = (JSONArray) v; List<Object> asList = new ArrayList<Object>(); for (int i = 0; i < array.length(); ++i) { asList.add(array.get(i)); }//from w w w . ja v a2 s . co m v = asList; } values.put(key, v); } CsvEntityContext context = new CsvEntityContextImpl(); for (FieldMapping mapping : schema.getFields()) { try { mapping.translateFromCSVToObject(context, values, wrapped); } catch (MissingRequiredFieldException ex) { throw new TransformSpecificationMissingArgumentException(line, ex.getFieldName()); } } }
From source file:org.onebusaway.gtfs_transformer.factory.TransformFactory.java
private Map<String, Object> getPropertyValuesFromJsonObject(JSONObject obj, Set<String> propertiesToExclude) throws JSONException { Map<String, Object> map = new HashMap<String, Object>(); for (@SuppressWarnings("unchecked") Iterator<String> it = obj.keys(); it.hasNext();) { String property = it.next(); if (propertiesToExclude.contains(property)) { continue; }/*from w w w .j av a 2s . co m*/ Object value = obj.get(property); if (property.equals(ARG_CLASS) || property.equals(ARG_FILE)) { continue; } map.put(property, value); } return map; }
From source file:org.onebusaway.gtfs_transformer.factory.TransformFactory.java
@SuppressWarnings("unchecked") private Map<String, Pair<String>> getEntityPropertiesAndStringReplacementsFromJsonObject(Class<?> entityType, JSONObject obj) throws JSONException { Map<String, Pair<String>> map = new HashMap<String, Pair<String>>(); for (Iterator<String> it = obj.keys(); it.hasNext();) { String property = it.next(); JSONObject pairs = obj.getJSONObject(property); String from = (String) pairs.keys().next(); String to = pairs.getString(from); Pair<String> pair = Tuples.pair(from, to); map.put(property, pair);/* w ww . j a va2s. c o m*/ } return map; }
From source file:com.liferay.mobile.android.http.HttpUtil.java
public static JSONArray upload(Session session, JSONObject command) throws Exception { String path = (String) command.keys().next(); Callback sessionCallback = session.getCallback(); if (sessionCallback != null) { sessionCallback = new UploadCallback((BaseCallback) sessionCallback); }// w w w . j a v a 2 s .co m Request request = new Request(session.getAuthentication(), Method.POST, session.getHeaders(), getURL(session, path), command.getJSONObject(path), session.getConnectionTimeout(), sessionCallback); Response response = client.upload(request); if (response == null) { return null; } else { return new JSONArray(UploadCallback.wrap(response.getBody())); } }