-1

Okay so I'm trying to parse the url and extract partial data.. However it doesn't seem to be extracting the exact data I want.. I assume it's extracting ID and not Value.

This is the code I'm using

            price = readUrl(apiUrl + String.valueOf(id)).split(",")[1].split(":")[1];
            String price2 = price.substring(0, price.length() - 1);
            return Integer.parseInt(price2);

the url I'm using is

https://api.rsbuddy.com/grandExchange?a=guidePrice&i=

parameter i = id of item, for this example we will use " 2619 "

which returns,

{"overall":49907,"buying":0,"buyingQuantity":0,"selling":49907,"sellingQuantity":2}

the information I want is

49907

from

{"overall":49907,
Lucy Beale
  • 89
  • 2
  • 7

2 Answers2

0

Use JSONObject:

  JSONObject jsonObject = new JSONObject(YOUR_STRING_YOU_WANT_TO_PARSE);
  Integer price = jsonObject.getInt("overall");
Mustapha Belmokhtar
  • 1,231
  • 8
  • 21
0

What you get from API is a JSON. So you can simply use JSONObject. https://docs.oracle.com/javaee/7/api/javax/json/JsonObject.html

You can do something like:

    jsonObject.getInt("overall");