-1

I am currently trying to find a WORKING and CURRENT JSON files that would be able to pull JSON info from a link such as

https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=CAD

With that link when you click on that it will display CURRENT prices for bitcoin.

All the libraries I downloaded for JSON is either fragmented or very out of date by years.

Why hasn’t JSON been standard for JAVA projects? But I digress.

If you click on the above link it displays info on bitcoin. I am only interested in one field and that is "price_cad". Which JSON is most recommended that is current and up-to-date and can achieve the desired results.

I reviewed the Question Parsing JSON in JAVA usng Gson. I found that this was not exactly what I was looking for.

ALSO!!!

The Bitcoin Stack Exchange is not active at all. I seen several posts with no answers and posted throughout the years sporadically. :(

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
BTCDude
  • 31
  • 7

1 Answers1

0
public static String btcvalue(){
        String msg = "";
        try {
            URL url = new URL("https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=CAD");
            System.setProperty("http.agent", "Chrome");
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
            String str = "";
            while (null != (str = br.readLine())) {
                msg = msg + str;
            }
            String decodedText = msg;
            String[] parts = decodedText.split("price_cad");
            String[] amnt = parts[1].split(",");
            String[] finn = amnt[0].split(":");
            msg = finn[1].replace("\"", "");
        } catch (Exception ex) {
            ex.printStackTrace();
            msg = "10.000";
        }
        return msg;
    }

This is the solution i found. Not exactly JSON but it still gets the desired value.

BTCDude
  • 31
  • 7