這裏是我又試了一次,但無濟於事....故障解析的JSONObject - 錯誤「字符串不能轉換爲JSONObject的」
我切換字符串將翻一番,改變以適應雙打作爲HashMap中的值好。仍然得到同樣的錯誤.....它很難找到只是拉一個沒有數組的jsonObject的示例
這裏有什麼問題?
{ 「基地」: 「EUR」, 「日期」: 「2017年8月25日」, 「速度」:{ 「AUD」:1.4919, 「BGN」:1.9558, 「BRL 「:3.7045, 「CAD」:1.4769, 「CHF」:1.139, 「萬元」:7.8596, 「捷克克朗」: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, 「諾」:9.2278, 「NZD」:1.6363, 「PHP」:60.327, 「PLN」:4.2598, 「RON」:4.5983, 「蹭」: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()'是多餘的。你已經得到一個字符串 –
嘗試Double australia = ratesObject.getDouble(「AUD」); –