I'm trying to get info from https://prices.runescape.wiki/api/v1/osrs/latest
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.GET()
.uri(URI.create("https://prices.runescape.wiki/api/v1/osrs/latest"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree(response.body());
JsonNode data = json.get("data");
List<Data> items = new ArrayList<>();
data.forEach(item -> {
Data d = new Data(
item.get("high").asInt(),
item.get("highTime").asInt(),
item.get("low").asInt(),
item.get("lowTime").asInt()
);
items.add(d);
});
Problem is the object is the itemID. So if I want the item id 6. I can't do it since it's not an attribute of the object.
"2":{"high":164,"highTime":1672078170,"low":160,"lowTime":1672078164} ``
"2" is the itemID and the object.
Below is when I loop through the arraylist and print it out
Data{high=157, highTime=1672071161, low=150, lowTime=1672071151}
Data{high=187987, highTime=1672071066, low=182005, lowTime=1672070881}
Data{high=189903, highTime=1672071052, low=186820, lowTime=1672070884}
Data{high=190000, highTime=1672070957, low=184882, lowTime=1672070984}
itemIDin your sample data."2":{ ... }(or you have an JSON-object with a property"2"). And there's noitemIDthat you've mentioned twice."2":{ ... }looks like aMap<Integer,Data>, can you share the rest JSON (for now it's unclear how to access it from the enclosing JSON-object) ?