weixin_33720078 2019-04-10 22:43 采纳率: 0%
浏览 58

如何从api文件获取?

i have one api . my data in my code has 2 section

"Meta Data": {…}
"Time Series (Daily)": {…}

i use this code for get json data and use in my chart

$.ajax({
    url: urls,        
    dataType: 'json',
    contentType: "application/json",
    success: function (data) {
        debugger;
        // split the data set into ohlc and volume
        var ohlc = [],
          volume = [],

          dataLength = data.length, // but this code is undefiend

how i can get "Time Series (Daily)" values ? thanks for read may solution

  • 写回答

1条回答 默认 最新

  • 普通网友 2019-04-11 21:46
    关注

    Given the state of the data you've given us, the correct way to get the data from the API endpoint here is to have

    $.ajax({
          url: urls,
          dataType: 'json',
          contentType: "application/json",
          success: function(data) {
            debugger;
            // split the data set into ohlc and volume
            var ohlc = [],
              volume = [],
    
              dataLength = data['Time Series (Daily)'].length,
              // rest of variable definitions
          });

    I would recommend, however, that you take the time to either snake case (some_property_here) or camel case (somePropertyHere) so that you don't have to use the data['string with spaces syntax']

    </div>
    
    评论

报告相同问题?