I am trying to split nested json data
private String TickData(String token) {
OkHttpClient client = new OkHttpClient().newBuilder().build();
Request request = new Request.Builder()
.url("https://history.truedata.in/getticks?symbol=NIFTY 50&from=211201T09:15:00&to=211201T15:30:00&response=json&bidask=1")
.method("GET", null)
.addHeader("Authorization", "Bearer " token)
.build();
try {
Response response = client.newCall(request).execute();
Log.d(TAG, "TickData: tick data response: " response.body().string());
String s = response.body().string();
Log.e(TAG, "TickData: s: " s );
} catch (Exception e) {
e.printStackTrace();
}
return tickdata;
}
this is my nested json data.
{"status":"Success","Records":[["2021-12-01T09:15:00",17104.4,0,0,0.0,0,0.0,0],["2021-12-01T09:15:00",17105.05,0,0,0.0,0,0.0,0],["2021-12-01T09:15:00",17082.0,0,0,0.0,0,0.0,0],["2021-12-01T09:15:00",17082.0,0,0,0.0,0,0.0,0],["2021-12-01T09:15:01",17079.75,0,0,0.0,0,0.0,0],["2021-12-01T09:15:01",17085.1,0,0,0.0,0,0.0,0],["2021-12-01T09:15:02",17088.65,0,0,0.0,0,0.0,0],["2021-12-01T09:15:03",17090.7,0,0,0.0,0,0.0,0],["2021-12-01T09:15:04",17095.3,0,0,0.0,0,0.0,0],["2021-12-01T09:15:05",17099.4,0,0,0.0,0,0.0,0],["2021-12-01T09:15:06",17106.05,0,0,0.0,0,0.0,0],["2021-12-01T09:15:06",17105.75,0,0,0.0,0,0.0,0],["2021-12-01T09:15:07",17109.0,0,0,0.0,0,0.0,0],["2021-12-01T09:15:07",17107.1,0,0,0.0,0,0.0,0],["2021-12-01T09:15:08",17110.85,0,0,0.0,0,0.0,0],["2021-12-01T09:15:08",17110.55,0,0,0.0,0,0.0,0],["2021-12-01T09:15:09",17120.9,0,0,0.0,0,0.0,0],["2021-12-01T09:15:09",17119.4,0,0,0.0,0,0.0,0],["2021-12-01T09:15:10",17125.9,0,0,0.0,0,0.0,0],["2021-12-01T09:15:10",17125.9,0,0,0.0,0,0.0,0],["2021-12-01T09:15:11",17128.3,0,0,0.0,0,0.0,0],["2021-12-01T09:15:11",17126.75,0,0,0.0,0,0.0,0],["2021-12-01T09:15:12",17130.45,0,0,0.0,0,0.0,0],["2021-12-01T09:15:12",17129.25,0,0,0.0,0,0.0,0],["2021-12-01T09:15:13",17131.55,0,0,0.0,0,0.0,0],["2021-12-01T09:15:13",17131.4,0,0,0.0,0,0.0,0],["2021-12-01T09:15:14",17134.85,0,0,0.0,0,0.0,0],["2021-12-01T09:15:14",17133.25,0,0,0.0,0,0.0,0],["2021-12-01T09:15:15",17136.65,0,0,0.0,0,0.0,0],["2021-12-01T09:15:15",17135.7,0,0,0.0,0,0.0,0],["2021-12-01T09:15:16",17137.35,0,0,0.0,0,0.0,0],["2021-12-01T09:15:16",17134.85,0,0,0.0,0,0.0,0],["2021-12-01T09:15:17",17135.95,0,0,0.0,0,0.0,0],["2021-12-01T09:15:19",17138.45,0,0,0.0,0,0.0,0],["2021-12-01T09:15:19",17136.0,0,0,0.0,0,0.0,0],["2021-12-01T09:15:20",17140.4,0,0,0.0,0,0.0,0],["2021-12-01T09:15:20",17138.85,0,0,0.0,0,0.0,0],["2021-12-01T09:15:21",17142.8,0,0,0.0,0,0.0,0],["2021-12-01T09:15:21",17138.7,0,0,0.0,0,0.0,0],["2021-12-01T09:15:22",17145.6,0,0,0.0,0,0.0,0],["2021-12-01T09:15:22",17144.35,0,0,0.0,0,0.0,0],["2021-12-01T09:15:23",17147.25,0,0,0.0,0,0.0,0],["2021-12-01T09:15:23",17146.55,0,0,0.0,0,0.0,0],["2021-12-01T09:15:24",17149.6,0,0,0.0,0,0.0,0],["2021-12-01T09:15:24",17149.25,0,0,0.0,0,0.0,0],["2021-12-01T09:15:24",17150.35,0,0,0.0,0,0.0,0],["2021-12-01T09:15:24",17147.15,0,0,0.0,0,0.0,0],["2021-12-01T09:15:25",17147.15,0,0,0.0,0,0.0,0],["2021-12-01T09:15:26",17148.15,0,0,0.0,0,0.0,0],["2021-12-01T09:15:27",17144.65,0,0,0.0,0,0.0,0],["2021-12-01T09:15:28",17142.55,0,0,0.0,0,0.0,0],["2021-12-01T09:15:29",17135.3,0,0,0.0,0,0.0,0],["2021-12-01T09:15:30",17136.45,0,0,0.0,0,0.0,0],["2021-12-01T09:15:31",17134.65,0,0,0.0,0,0.0,0],["2021-12-01T09:15:32",17127.55,0,0,0.0,0,0.0,0],["2021-12-01T09:15:33",17127.3,0,0,0.0,0,0.0,0],["2021-12-01T09:15:34",17126.95,0,0,0.0,0,0.0,0],["2021-12-01T09:15:35",17128.2,0,0,0.0,0,0.0,0],["2021-12-01T09:15:36",17129.55,0,0,0.0,0,0.0,0],["2021-12-01T09:15:37",17130.4,0,0,0.0,0,0.0,0],["2021-12-01T09:15:38",17133.35,0,0,0.0,0,0.0,0],["2021-12-01T09:15:39",17134.2,0,0,0.0,0,0.0,0],["2021-12-01T09:15:40",17136.1,0,0,0.0,0,0.0,0],["2021-12-01T09:15:41",17137.55,0,0,0.0,0,0.0,0],["2021-12-01T09:15:42",17138.3,0,0,0.0,0,0.0,0],["2021-12-01T09:15:43",17145.05,0,0,0.0,0,0.0,0],["2021-12-01T09:15:44",17145.6,0,0,0.0,0,0.0,0],["2021-12-01T09:15:46",17146.3,0,0,0.0,0,0.0,0],["2021-12-01T09:15:47",17148.95,0,0,0.0,0,0.0,0],["2021-12-01T09:15:48",17151.95,0,0,0.0,0,0.0,0],["2021-12-01T09:15:48",17150.2,0,0,0.0,0,0.0,0],["2021-12-01T09:15:49",17152.55,0,0,0.0,0,0.0,0],["2021-12-01T09:15:49",17152.55,0,0,0.0,0,0.0,0],["2021-12-01T09:15:50",17154.35,0,0,0.0,0,0.0,0],["2021-12-01T09:15:50",17153.9,0,0,0.0,0,0.0,0],["2021-12-01T09:15:51",17155.4,0,0,0.0,0,0.0,0],["2021-12-01T09:15:51",17149.45,0,0,0.0,0,0.0,0],["2021-12-01T09:15:52",17157.35,0,0,0.0,0,0.0,0],["2021-12-01T09:15:52",17156.3,0,0,0.0,0,0.0,0],["2021-12-01T09:15:52",17158.3,0,0,0.0,0,0.0,0],["2021-12-01T09:15:52",17155.65,0,0,0.0,0,0.0,0],["2021-12-01T09:15:53",17157.7,0,0,0.0,0,0.0,0]]}
I have to split the record first after that collect all array data inside on it.
CodePudding user response:
You can perhaps use Jackson api to parse it.
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
then you can use following
String jsonString = "{\"status\":\"Success\",\"Records\":[[\"2021-12-01T09:15:00\",17104.4,0,0,0.0,0,0.0,0],[\"2021-12-01T09:15:00\",17105.05,0,0,0.0,0,0.0,0]]}";
ObjectMapper mapper = new ObjectMapper();
try {
Map map = mapper.readValue(jsonString, Map.class);
List<List> recordsList = (List<List>)map.get("Records");
// Now you can access the elements directly as following
System.out.println(recordsList.get(0).get(0));
} catch (JsonProcessingException e) {
e.printStackTrace();
}