Raza Hanafi
Raza Hanafi

Reputation: 45

Api data extraction

I am using an API and I get this result when i use the getJSON method. I have tried it in my codepen console and i get the same data but for some reason I can't figure out how to get to a specific text in the data. so for example: console.log(data) gives me the entire result below. how do i make it give me just the exchange rate. console.log(data[1][4]) i've tried several methods still failing.

{
"Realtime Currency Exchange Rate": {
"1. From_Currency Code": "USD",
"2. From_Currency Name": "United States Dollar",
"3. To_Currency Code": "JPY",
"4. To_Currency Name": "Japanese Yen",
"5. Exchange Rate": "111.28450000",
"6. Last Refreshed": "2017-11-23 00:24:23",
"7. Time Zone": "UTC"
}
}

What I've got in my JS:

$.getJSON(realtime, function(data) {
   console.log(data);
});

The result

Upvotes: 0

Views: 74

Answers (1)

kgangadhar
kgangadhar

Reputation: 5088

Try this :

data["Realtime Currency Exchange Rate"] and

data["Realtime Currency Exchange Rate"]["From_Currency Code"]

Upvotes: 1

Related Questions