Below is the URL to get the 1st batch list of the Bithumb candle chart
https://api.bithumb.com/public/candlestick/ETH/1m
{"status":"0000","data":[[1582464360000,"321000","320900","321000","320900","11.7071"],[],[]]}
I want to get the data How do I parse?
List(string[]) data = ?
org.json.JSONObject
Library in use
@Test
public void parseFromString() {
final String jsonString = "{\"status\":\"0000\",\"data\":[[1582464360000,\"321000\",\"320900\",\"321000\",\"320900\",\"11.7071\"],[],[]]}";
JSONObject object = new JSONObject(jsonString);
JSONArray data = (JSONArray) object.get("data");
Assert.assertEquals(JSONArray.class, data.get(0).getClass());
JSONArray firstElement = (JSONArray) data.get(0);
Assert.assertEquals(Long.class, firstElement.get(0).getClass());
Assert.assertEquals(String.class, firstElement.get(1).getClass());
JSONArray secondEmptyElement = (JSONArray) data.get(1);
Assert.assertEquals(0, secondEmptyElement.length());
}
Just do it like above.
Actually, it is more convenient to use fastxml-jackson or Google-Gson than this.
You can approach it in the form below.
jsonStr = "{\"status\":\"0000\",\"data\":[[1582464360000,\"321000\",\"320900\",\"321000\",\"320900\",\"11.7071\"],[],[]]}"
JSONObject jsonObj = new JSONObject(jsonStr);
JSONArray jsonArray = jsonObj .getJSONArray("data");
© 2024 OneMinuteCode. All rights reserved.