Here is what I tried again but to no avail....
I switch String to double and change the values in the hashmap to accommodate doubles as well. Still getting the same error.....It difficult to find example of just pulling a jsonObject without an array
What the issue here ???
{ "base": "EUR", "date": "2017-08-25", "rates": { "AUD": 1.4919, "BGN": 1.9558, "BRL": 3.7045, "CAD": 1.4769, "CHF": 1.139, "CNY": 7.8596, "CZK": 26.084, "DKK": 7.4391, "GBP": 0.92083, "HKD": 9.2372, "HRK": 7.414, "HUF": 304.68, "IDR": 15758.0, "ILS": 4.2453, "INR": 75.598, "JPY": 129.59, "KRW": 1327.0, "MXN": 20.844, "MYR": 5.0456, "NOK": 9.2278, "NZD": 1.6363, "PHP": 60.327, "PLN": 4.2598, "RON": 4.5983, "RUB": 69.831, "SEK": 9.5053, "SGD": 1.6055, "THB": 39.332, "TRY": 4.108, "USD": 1.1808, "ZAR": 15.549 } }
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
JSONObject jsonObj2 = jsonObj.getJSONObject("rates");
double australia = jsonObj2.getDouble("AUD");
double bulgarian = jsonObj2.getDouble("BDN");
double brazil = jsonObj2.getDouble("BRL");
double canadian = jsonObj2.getDouble("CAD");
double swissfrank = jsonObj2.getDouble("CHF");
double chinnese = jsonObj2.getDouble("CNY");
double Czech = jsonObj2.getDouble("CZK");
double Danish = jsonObj2.getDouble("DKK");
double british = jsonObj2.getDouble("GBP");
double hongkong = jsonObj2.getDouble("HKD");
double croatian = jsonObj2.getDouble("HRK");
double hungarian = jsonObj2.getDouble("HUF");
double indonesian = jsonObj2.getDouble("IDR");
double israeli = jsonObj2.getDouble("ILS");
double indian = jsonObj2.getDouble("INR");
double japan = jsonObj2.getDouble("JPY");
double korean = jsonObj2.getDouble("KRW");
double mexican = jsonObj2.getDouble("MXN");
double malaysian = jsonObj2.getDouble("MYR");
double norwegian = jsonObj2.getDouble("NOK");
double newzealand = jsonObj2.getDouble("NZD");
double philippino = jsonObj2.getDouble("PHP");
double polish = jsonObj2.getDouble("PLN");
double romanian = jsonObj2.getDouble("RON");
double russian = jsonObj2.getDouble("RUB");
double swedish = jsonObj2.getDouble("SEK");
double singapore = jsonObj2.getDouble("SGD");
double thai = jsonObj2.getDouble("THB");
double turkish = jsonObj2.getDouble("TRY");
double usa = jsonObj2.getDouble("USD");
double southafrican = jsonObj2.getDouble("ZAR");
// tmp hash map for single contact
HashMap<String, Double> contact = new HashMap<>();
// adding each child node to HashMap key => value
contact.put("AUD", australia);
contact.put("BDN", bulgarian);
contact.put("BRL", brazil);
contact.put("CAD", canadian);
contact.put("CHF", swissfrank);
contact.put("CNY", chinnese);
contact.put("CZK", Czech);
contact.put("DKK", Danish);
contact.put("GBP", british);
contact.put("HKD", hongkong);
contact.put("HRK", croatian);
contact.put("HUF", hungarian);
contact.put("IDR", indonesian);
contact.put("ILS", israeli);
contact.put("INR", indian);
contact.put("JPY", japan);
contact.put("KRW", korean);
contact.put("MXN", mexican);
contact.put("MYR", malaysian);
contact.put("NOK", norwegian);
contact.put("NZD", newzealand);
contact.put("PHP", philippino);
contact.put("PLN", polish);
contact.put("RON", romanian);
contact.put("RUB", russian);
contact.put("SEK", swedish);
contact.put("SGD", singapore);
contact.put("THB", thai);
contact.put("TRY", turkish);
contact.put("USA", usa);
contact.put("ZAR", southafrican);
// adding contact to contact list
contactList.add(contact);
getString("AUD").toString()
is redundant. You already are getting a string – OneCricketeer