Skip to content Skip to sidebar Skip to footer

Extracting Data From Json Object In JQuery Or JS

I want to use the currency data provided by https://raw.github.com/currencybot/open-exchange-rates/master/latest.json As an initial test, I've created a cut-down version of this as

Solution 1:

var obj = [
{
    "disclaimer": "This data is collected from various providers and provided free of charge for informational purposes only, with no guarantee whatsoever of accuracy, validity, availability, or fitness for any purpose; use at your own risk. Other than that, have fun! More info: http://openexchangerates.org/terms/",
    "license": "Data collected from various providers with public-facing APIs; copyright may apply; not for resale; no warranties given. Full license info: http://openexchangerates.org/license/",
    "timestamp": 1339036116,
    "base": "USD",
    "rates": {
        "EUR": 0.795767,
        "GBP": 0.645895,
        "JPY": 79.324997,
        "USD": 1
    }
}];

obj[0].rates.EUR; // output: 0.795767

or

obj[0].rates['EUR']; output: //0.795767

DEMO

If you want to isolate rates in another variable and use that variable then try like following:

var rates = obj[0].rates;

Now,

rates.EUR;
rates.GBP;

and so on.


Solution 2:

You can also use JSON.parse() function of Javascript to convert JSON String into Javascript JSON object.

var JSONObject = JSON.parse("{'value1' : 1, 'value2' : 2}");
console.log(JSONObject.value1);  // Prints '1'..

Solution 3:

data contains FRELD6 try to :

var reldte;
var sdata = JSON.parse(data);
 $(sdata).each(function () {
        reldte = RefineDate(this.FRELD6.toString());
}

Post a Comment for "Extracting Data From Json Object In JQuery Or JS"