-1

I am trying to extract from the following data:

{
  "USD" : {"15m" : 478.68, "last" : 478.68, "buy" : 478.55, "sell" : 478.68,  "symbol" : "$"},
  "JPY" : {"15m" : 51033.99, "last" : 51033.99, "buy" : 51020.13, "sell" : 51033.99,  "symbol" : "¥"},
}

I want to get the USD last price.

my code so far is as follows:

JSONObject json = new JSONObject(IOUtils.toString(new URL("https://blockchain.info/ticker").openStream()));
System.out.println(json.get("USD"));

This gives me the following output:

{"symbol":"$","last":651.98,"buy":651.02,"sell":651.98,"15m":651.98}

I just want to get the last USD Price, i have no idea how to do it! Can anyone enlighten me.

Thanks!

HashTables
  • 392
  • 2
  • 7
  • 22

1 Answers1

0
JSONObject json = new JSONObject(IOUtils.toString(new URL("https://blockchain.info/ticker").openStream()));
double last = json.getJSONObject("USD").getDouble("last");
nicholas79171
  • 1,203
  • 2
  • 15
  • 28