Kemat Rochi
Kemat Rochi

Reputation: 952

How to parse a JSON file using jQuery?

I am making an AJAX call to an API like this,

$.ajax({
        url: 'http://dev.markitondemand.com/MODApis/Api/v2/InteractiveChart/jsonp?parameters={"Normalized":false,"NumberOfDays":1095,"DataPeriod":"Day","Elements":[{"Symbol":"AAPL","Type":"price","Params":["ohlc"]}]}',
        dataType: 'jsonp',
        success: function(data) {
                //output = JSON.stringify(data, null, '\t')
                $('#container').html(JSON.stringify(data.Elements.Currency, null, '\t'));

        }
    });

The resultant JSON file is huge and I want to extract value of Elements->Currency.

What am I doing wrong here?

Upvotes: 2

Views: 201

Answers (2)

madalinivascu
madalinivascu

Reputation: 32354

Use the dot notation, no need to stringify the data

success: function(data) {
               alert(data.Positions);
        }

or use a loop for elements:

success: function(data) {
              $.each(data.Elements,function(i,v){
                 console.log(v.Currency);
              });
        }

see demo

Upvotes: 1

Rohìt Jíndal
Rohìt Jíndal

Reputation: 27192

Try this :

success: function(data) {
               console.log(data.Elements[0].Currency);
        }

Upvotes: 2

Related Questions