Reputation: 6200
I'm looking at an API here:
https://openexchangerates.org/documentation
The call is:
http://openexchangerates.org/api/latest.json?app_id=YOUR_APP_ID
And the return is:
{
"disclaimer": "Exchange rates provided by [...]",
"license": "Data collected and blended [...]",
"timestamp": 1319730758,
"base": "USD",
"rates": {
"AED": 3.672626,
"AFN": 48.3775,
"ALL": 110.223333,
"AMD": 409.604993,
/* 160 fx rates available - see currencies.json */
"YER": 215.035559,
"ZAR": 8.416205,
"ZMK": 4954.411262,
"ZWL": 322.355011
}
}
My question here is, how do I use this to display the INR rate which is returned? In my fiddle, I've only got as far as calling the API with my App ID which needs to be displayed in the <span class="display">
. I'm not very fluent with JSON and it's associated functions.
Thanks!
Upvotes: 1
Views: 1270
Reputation: 5647
A jason object can be accessed just like a normal object in javascript. In this case you can use:
data.rates.INR
To get that into your span, do this
$('.display').html( data.rates.INR)
inside your function
lastly, don't forget to change your fiddle to have jQuery as the framework over on the left
Upvotes: 3