Измените JSONArrayListener
на JSONObjectListener
на OnResponse()
. Кроме того, добавьте свою метку даты и времени внутри объекта следующим образом.
Отсюда:
{
"symbol": "AAPL",
"stock_exchange_short": "NASDAQ",
"timezone_name": "America/New_York",
"intraday": {
2018-10-19 15:59:00: {
"open": "219.49",
"close": "219.23",
"high": "219.61",
"low": "219.19",
"volume": "302415",
},
2018-10-19 15:58:00: {
"open": "219.62",
"close": "219.48",
"high": "219.70",
"low": "219.48",
"volume": "173762",
},
2018-10-19 15:57:00: {
"open": "219.54",
"close": "219.64",
"high": "219.66",
"low": "219.46",
"volume": "130992",
},
2018-10-19 15:56:00: {
"open": "219.71",
"close": "219.57",
"high": "219.77",
"low": "219.57",
"volume": "113398",
},
...
}
}
до
{
"symbol": "AAPL",
"stock_exchange_short": "NASDAQ",
"timezone_name": "America/New_York",
"intraday": {
"data": [
{
"open": "219.49",
"close": "219.23",
"high": "219.61",
"low": "219.19",
"volume": "302415",
"datetimestamp": "2018-10-19 15:59:00"
},
{
"open": "219.62",
"close": "219.48",
"high": "219.70",
"low": "219.48",
"volume": "173762",
"datetimestamp": "2018-10-19 15:59:00"
},
{
"open": "219.54",
"close": "219.64",
"high": "219.66",
"low": "219.46",
"volume": "130992",
"datetimestamp": "2018-10-19 15:59:00"
},
{
"open": "219.71",
"close": "219.57",
"high": "219.77",
"low": "219.57",
"volume": "113398",
"datetimestamp": "2018-10-19 15:59:00"
}
]
}
}
Затем получите данные, выполнив это (кстати, я использую AndroidNetworking
):
AndroidNetworking.get("your URL")
.addHeaders("your Header")
.setPriority(Priority.HIGH)
.build()
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
try{
//getting intraday as a JSONObject
JSONObject jsonObject = response.getJSONObject("intraday");
HashMap<String, String> yourMap = new HashMap();
//getting the data as a JSONArray as given on my example
JSONArray jsonArray = jsonObject.getJSONArray("data");
for (int x = 0;x< jsonArray.length();x++){
JSONObject jsonObject1 = jsonArray.getJSONObject(x);
//getting the data inside the json object
double open = jsonObject1.getDouble("open");
double close = jsonObject1.getDouble("close");
double high = jsonObject1.getDouble("high");
double low = jsonObject1.getDouble("low");
int volume = jsonObject1.getInt("volume"); //or getDouble it depends on your data
String dateTimeStamp = jsonObject1.getString("datetimestamp");
try {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = df.parse(dateTimeStamp);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String convertedDateTimeStamp = sdf.format(date);
} catch (ParseException e) {
e.printStackTrace();
}
yourMap.put(convertedDateTimeStamp, String.valueOf(close))
}
}catch (Throwable throwable){
throwable.printStackTrace();
}
}
@Override
public void onError(ANError anError) {
}
});