List of usage examples for org.json JSONArray get
public Object get(int index) throws JSONException
From source file:com.github.koraktor.steamcondenser.community.GameItem.java
/** * Creates a new instance of a GameItem with the given data * * @param inventory The inventory this item is contained in * @param itemData The data specifying this item * @throws WebApiException on Web API errors */// w w w . j av a2 s . co m public GameItem(GameInventory inventory, JSONObject itemData) throws SteamCondenserException { this.inventory = inventory; try { this.defindex = itemData.getInt("defindex"); this.backpackPosition = (int) itemData.getLong("inventory") & 0xffff; this.count = itemData.getInt("quantity"); this.craftable = !itemData.optBoolean("flag_cannot_craft"); this.id = itemData.getInt("id"); this.itemClass = this.getSchemaData().getString("item_class"); this.itemSet = this.inventory.getItemSchema().getItemSets() .get(this.getSchemaData().optString("item_set")); this.level = itemData.getInt("level"); this.name = this.getSchemaData().getString("item_name"); this.preliminary = (itemData.getLong("inventory") & 0x40000000) != 0; this.originalId = itemData.getInt("original_id"); this.quality = this.inventory.getItemSchema().getQualities().get(itemData.getInt("quality")); this.tradeable = !itemData.optBoolean("flag_cannot_trade"); this.type = this.getSchemaData().getString("item_type_name"); if (itemData.has("origin")) { this.origin = this.inventory.getItemSchema().getOrigins().get(itemData.getInt("origin")); } JSONArray attributesData = this.getSchemaData().optJSONArray("attributes"); if (attributesData == null) { attributesData = new JSONArray(); } if (itemData.has("attributes")) { JSONArray itemAttributes = itemData.getJSONArray("attributes"); for (int i = 0; i < itemAttributes.length(); i++) { attributesData.put(itemAttributes.get(i)); } } this.attributes = new ArrayList<JSONObject>(); for (int i = 0; i < attributesData.length(); i++) { JSONObject attributeData = attributesData.getJSONObject(i); Object attributeKey = attributeData.opt("defindex"); if (attributeKey == null) { attributeKey = attributeData.opt("name"); } if (attributeKey != null) { JSONObject schemaAttributeData = inventory.getItemSchema().getAttributes().get(attributeKey); for (String key : JSONObject.getNames(schemaAttributeData)) { attributeData.put(key, schemaAttributeData.get(key)); } this.attributes.add(attributeData); } } } catch (JSONException e) { throw new WebApiException("Could not parse JSON data.", e); } }
From source file:com.grillecube.common.utils.JSONHelper.java
/** load a vector3f from a JSON array of 3 floats */ public static Vector3f jsonArrayToVector3f(JSONArray array) { return (new Vector3f(jsonObjectToFloat(array.get(0)), jsonObjectToFloat(array.get(1)), jsonObjectToFloat(array.get(2)))); }
From source file:com.grillecube.common.utils.JSONHelper.java
/** json array to float array */ public static float[] jsonArrayToFloatArray(JSONArray array) { float[] floats = new float[array.length()]; for (int i = 0; i < floats.length; i++) { floats[i] = jsonObjectToFloat(array.get(i)); }//from ww w. j a v a2s . com return (floats); }
From source file:com.platform.APIClient.java
public String getLatestVersion() { String latestVersion = null;/*from ww w . ja v a2 s .com*/ String response = null; try { response = sendRequest( new Request.Builder().get() .url(String.format("%s/assets/bundles/%s/versions", BASE_URL, BREAD_BUY)).build(), false, 0).body().string(); } catch (IOException e) { e.printStackTrace(); } String respBody; respBody = response; try { JSONObject versionsJson = new JSONObject(respBody); JSONArray jsonArray = versionsJson.getJSONArray("versions"); if (jsonArray.length() == 0) return null; latestVersion = (String) jsonArray.get(jsonArray.length() - 1); } catch (JSONException e) { e.printStackTrace(); } return latestVersion; }
From source file:org.envirocar.app.json.TrackEncoder.java
private JSONObject createTrackProperties(Track track, String trackSensorName) throws JSONException { JSONObject result = new JSONObject(); result.put("sensor", trackSensorName); result.put("description", track.getDescription()); result.put("name", track.getName()); if (track.getMetadata() != null) { JSONObject json = track.getMetadata().toJson(); JSONArray names = json.names(); for (int i = 0; i < names.length(); i++) { result.put(names.get(i).toString(), json.getString(names.get(i).toString())); }// w w w. ja v a 2 s .c om } return result; }
From source file:com.basho.riak.client.mapreduce.filter.SetMemberFilter.java
public SetMemberFilter(JSONArray setMembers) throws JSONException { args.put("set_member"); for (int i = 0; i < setMembers.length(); i++) { args.put(setMembers.get(i)); }// w ww . java 2 s .c o m }
From source file:com.facebook.share.internal.ShareInternalUtility.java
public static JSONArray removeNamespacesFromOGJsonArray(JSONArray jsonArray, boolean requireNamespace) throws JSONException { JSONArray newArray = new JSONArray(); for (int i = 0; i < jsonArray.length(); ++i) { Object value = jsonArray.get(i); if (value instanceof JSONArray) { value = removeNamespacesFromOGJsonArray((JSONArray) value, requireNamespace); } else if (value instanceof JSONObject) { value = removeNamespacesFromOGJsonObject((JSONObject) value, requireNamespace); }/*from www .j a va2 s . com*/ newArray.put(value); } return newArray; }
From source file:org.span.manager.ChangeSettingsActivity.java
private void updateConfig(String key) { boolean updateFlag = false; Map<String, String> oldcfgmap = new TreeMap<String, String>(manetcfg.toMap()); if (key.equals("uidpref")) { String userId = sharedPreferences.getString("uidpref", ManetConfig.USER_ID_DEFAULT.toString()); manetcfg.setUserId(userId);// w w w .jav a 2 s. c om } else if (key.equals("encalgorithmpref")) { String encAlgorithm = sharedPreferences.getString("encalgorithmpref", ManetConfig.WIFI_ENCRYPTION_ALGORITHM_DEFAULT.toString()); manetcfg.setWifiEncryptionAlgorithm(WifiEncryptionAlgorithmEnum.fromString(encAlgorithm)); updateFlag = true; } else if (key.equals("encsetuppref")) { String encSetupMethod = sharedPreferences.getString("encsetuppref", ManetConfig.WIFI_ENCRYPTION_SETUP_METHOD_DEFAULT.toString()); manetcfg.setWifiEncryptionSetupMethod(WifiEncryptionSetupMethodEnum.fromString(encSetupMethod)); } else if (key.equals("passwordpref")) { String encPassword = sharedPreferences.getString("passwordpref", ManetConfig.WIFI_ENCRYPTION_PASSWORD_DEFAULT); manetcfg.setWifiEncryptionPassword(encPassword); } else if (key.equals("ssidpref")) { String wifiSsid = sharedPreferences.getString("ssidpref", ManetConfig.WIFI_ESSID_DEFAULT); manetcfg.setWifiSsid(wifiSsid); } else if (key.equals("channelpref")) { String wifiChannel = sharedPreferences.getString("channelpref", ManetConfig.WIFI_CHANNEL_DEFAULT.toString()); manetcfg.setWifiChannel(WifiChannelEnum.fromString(wifiChannel)); } else if (key.equals("txpowerpref")) { String wifiTxpower = sharedPreferences.getString("txpowerpref", ManetConfig.WIFI_TXPOWER_DEFAULT.toString()); manetcfg.setWifiTxPower(WifiTxpowerEnum.fromString(wifiTxpower)); } else if (key.equals("interfacepref")) { String wifiInterface = sharedPreferences.getString("interfacepref", ManetConfig.WIFI_INTERFACE_DEFAULT.toString()); manetcfg.setWifiInterface(wifiInterface); updateFlag = true; } else if (key.equals("ippref")) { String ipAddress = sharedPreferences.getString("ippref", ManetConfig.IP_ADDRESS_DEFAULT); manetcfg.setIpAddress(ipAddress); } else if (key.equals("dnspref")) { String dnsServer = sharedPreferences.getString("dnspref", ManetConfig.DNS_SERVER_DEFAULT); manetcfg.setDnsServer(dnsServer); } else if (key.equals("bluetoothonpref")) { final Boolean bluetoothOn = sharedPreferences.getBoolean("bluetoothonpref", ManetConfig.ADHOC_MODE_DEFAULT == AdhocModeEnum.BLUETOOTH); if (bluetoothOn) { manetcfg.setAdhocMode(AdhocModeEnum.BLUETOOTH); } else { manetcfg.setAdhocMode(AdhocModeEnum.WIFI); } updateFlag = true; } else if (key.equals("bluetoothkeepwifipref")) { Boolean btKeepWifi = sharedPreferences.getBoolean("bluetoothkeepwifipref", !ManetConfig.BLUETOOTH_DISABLE_WIFI_DEFAULT); manetcfg.setDisableWifiWhenUsingBluetooth(!btKeepWifi); } else if (key.equals("bluetoothdiscoverablepref")) { Boolean btDiscoverable = sharedPreferences.getBoolean("bluetoothdiscoverablepref", ManetConfig.BLUETOOTH_DISCOVERABLE_DEFAULT); manetcfg.setBlutoothDiscoverableWhenInAdhocMode(btDiscoverable); } else if (key.equals("routingprotocolpref")) { String routingProtocol = sharedPreferences.getString("routingprotocolpref", ManetConfig.ROUTING_PROTOCOL_DEFAULT); manetcfg.setRoutingProtocol(routingProtocol); } else if (key.equals("ignorepref")) { List<String> ignoreList = new ArrayList<String>(); try { JSONArray array = new JSONArray(sharedPreferences.getString("ignorepref", "[]")); for (int i = 0; i < array.length(); i++) { ignoreList.add(array.get(i).toString()); } } catch (JSONException e) { e.printStackTrace(); } manetcfg.setRoutingIgnoreList(ignoreList); } else if (key.equals("gatewaypref")) { String gatewayInterface = sharedPreferences.getString("gatewaypref", ManetConfig.GATEWAY_INTERFACE_DEFAULT.toString()); manetcfg.setGatewayInterface(gatewayInterface); updateFlag = true; } else if (key.equals("screenonpref")) { Boolean screenOn = sharedPreferences.getBoolean("screenonpref", ManetConfig.SCREEN_ON_DEFAULT); manetcfg.setScreenOnWhenInAdhocMode(screenOn); } Map<String, String> newcfgmap = manetcfg.toMap(); dirtyFlag |= !oldcfgmap.equals(newcfgmap); if (updateFlag) { updateView(); // selecting some options may change the available choices for other options } }
From source file:com.hichinaschool.flashcards.utils.ConvUtils.java
public static Object[] jsonArray2Objects(JSONArray array) { Object[] o = new Object[array.length()]; for (int i = 0; i < array.length(); i++) { try {//from ww w .ja va 2s.c o m o[i] = array.get(i); } catch (JSONException e) { throw new RuntimeException(e); } } return o; }
From source file:com.netatmo.weatherstation.api.NetatmoUtils.java
public static Measures parseMeasures(JSONObject response, String[] types) { Measures measures = new Measures(); try {/* w ww.j a va2 s. c o m*/ JSONObject body = response.getJSONArray("body").getJSONObject(0); String beginTime = body.getString("beg_time"); measures.setBeginTime((beginTime == null) ? 0 : Long.parseLong(beginTime) * 1000); JSONArray values = body.getJSONArray("value").getJSONArray(0); for (int i = 0; i < types.length; i++) { if (types[i].equals(Params.TYPE_TEMPERATURE)) { measures.setTemperature(getStringFromObject(values.get(i))); } else if (types[i].equals(Params.TYPE_CO2)) { measures.setCO2(getStringFromObject(values.get(i))); } else if (types[i].equals(Params.TYPE_HUMIDITY)) { measures.setHumidity(getStringFromObject(values.get(i))); } else if (types[i].equals(Params.TYPE_PRESSURE)) { measures.setPressure(getStringFromObject(values.get(i))); } else if (types[i].equals(Params.TYPE_NOISE)) { measures.setNoise(getStringFromObject(values.get(i))); } else if (types[i].equals(Params.TYPE_MIN_TEMP)) { measures.setMinTemp(getStringFromObject(values.get(i))); } else if (types[i].equals(Params.TYPE_MAX_TEMP)) { measures.setMaxTemp(getStringFromObject(values.get(i))); } } } catch (JSONException e) { e.printStackTrace(); } return measures; }