2

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?

1
  • 1
    data.Elements is an array data.Elements[0].Currency Commented Apr 4, 2016 at 3:25

2 Answers 2

2

Try this :

success: function(data) {
               console.log(data.Elements[0].Currency);
        }
Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Have no idea who marked you down. But your updated answer really helped a lot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.