lundi 2 mars 2015

JSON parsing help


url = http://ift.tt/1ByYIQp;


expected result:


History entry: 2014-06-23 - 1.68015


History entry: 2014-06-22 - 1.6716


History entry: 2014-06-21 - 1.6716


History entry: 2014-06-20 - 1.6716


History entry: 2014-06-19 - 1.66575


History entry: 2014-06-18 - 1.6645


History entry: 2014-06-17 - 1.665


real results:


History entry: 2014-06-23 - 1.68015


History entry: 2014-06-21 - 1.6716


History entry: 2014-06-19 - 1.66575


History entry: 2014-06-22 - 1.6716


History entry: 2014-06-18 - 1.6645


History entry: 2014-06-17 - 1.665


History entry: 2014-06-20 - 1.6716


private String[] getCurrencyDataFromJson(String historyJsonStr, int numDays) throws JSONException {



// These are the names of the JSON objects that need to be extracted.
final String OWM_RATES = "rates";
final String OWM_utctime = "utctime";
final String OWM_rate = "rate";


JSONObject historyJson = new JSONObject(historyJsonStr);
JSONObject daysHistory = historyJson.getJSONObject("rates");

int i=0;
String[] resultStrs = new String[numDays];

Iterator<String> keys = daysHistory.keys();
String date;


while (keys.hasNext()) {
date = (String) keys.next();
JSONObject values = daysHistory.getJSONObject(date);
Double histrate = values.getDouble("rate");
resultStrs[i] = date + " - " + histrate;
i++;

}

for (String s : resultStrs) {
Log.v(LOG_TAG, "History entry: " + s);
}
return resultStrs;

}




Aucun commentaire:

Enregistrer un commentaire