I have a problem.
Earlier, I parsed multiple objects from 1 single JSON to an ArrayList<Object>
. This worked great, but now I need to do something different and I have no idea how to this. I have the following JSON:
{
"Market":"USDT",
"Coin":"BTC",
"Candles":{
"USDT":{
"BTC":{
"3h":[
{
"Close":"used"
}
],
"1h":[
{
"EMA20":"used",
"EMA200":"used"
}
],
"5m":[
{
"EMA5":"used",
"EMA20":"used"
},
{
"EMA5":"used",
"EMA20":"used"
}
]
}
}
}
}
From this JSON I want to get an ArrayList<String>
with only the values: "3h", "1h", "5m".
The values inside the array don't matter for me, I just need those 3 periods. Here is the json parser I used for parsing something to a class:
public ArrayList<Agent> parseJsonToList(String StrJSON) {
Gson gson = new GsonBuilder().registerTypeAdapter(LocalDateTime.class, (JsonDeserializer<LocalDateTime>) (json, type, jsonDeserializationContext) -> {
try{
return LocalDateTime.parse(json.getAsJsonPrimitive().getAsString(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} catch (DateTimeParseException e){
return LocalDateTime.parse(json.getAsJsonPrimitive().getAsString(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS"));
}
}).create();
Type listType = new TypeToken<ArrayList<Agent>>() {}.getType();
return gson.fromJson(StrJSON, listType);
}
Now how can I get those 3 values from my new JSON, without creating Classes (if possible)?