0

Hi im working on an android app and i need to fetch the current value of 1 USD dollar in rupees from the internet using the link below or from any other website..

https://www.google.com/search?q=1+usd+in+inr&gws_rd=ssl

when i tried to parse the link using URL functions the whole html contents of the page are fetched..Can anyone help me fetch only the rupee value of 1 USD dollar in java..

Pino
  • 7,468
  • 6
  • 50
  • 69
Mano
  • 67
  • 1
  • 13

1 Answers1

0

use this to get current USD to INR in json format:

URL url = new URL("http://www.freecurrencyconverterapi.com/api/v2/convert?q=USD_INR&compact=y");
        BufferedReader br =  new BufferedReader(new InputStreamReader(url.openStream()));
        String json=br.readLine();
        JSONObject jsonObj = new JSONObject(json);
        JSONObject valObj = jsonObj.getJSONObject("USD_INR");
        System.out.println("Current USD to INR conversion is 1 USD = "+valObj.get("val")+ " INR");

prints

Current USD to INR conversion is 1 USD = 60.27 INR
user3487063
  • 3,672
  • 1
  • 17
  • 24