douyou2234 2017-11-04 01:00
浏览 45
已采纳

解析Json对象

I have a json object like below. I need to locate and load the "data" value in each variable for further processing. I went through few basic PHP examples here, but didn't work. Any help is greatly appreciated.

{
"dataset":
    {


    "id":9775409,
    "dataset_code":"AAPL",
    "database_code":"WIKI",
    "name":"Apple Inc (AAPL) Prices, Dividends, Splits and Trading Volume",
    "description":"End of day open, high, low, close and volume, dividends and splits, and split/dividend adjusted open, high, low close and volume for Apple Inc. (AAPL). Ex-Dividend is non-zero on ex-dividend dates. Split Ratio is 1 on non-split dates. Adjusted prices are calculated per CRSP (\u003ca href=\"http://www.crsp.com/products/documentation/crsp-calculations\" rel=\"nofollow\" target=\"blank\"\u003ewww.crsp.com/products/documentation/crsp-calculations\u003c/a\u003e)

\u003cp\u003eThis data is in the public domain. You may copy, distribute, disseminate or include the data in other products for commercial and/or noncommercial purposes.\u003c/p\u003e
\u003cp\u003eThis data is part of Quandl's Wiki initiative to get financial data permanently into the public domain. Quandl relies on users like you to flag errors and provide data where data is wrong or missing. Get involved: \u003ca href=\"mailto:connect@quandl.com\" rel=\"nofollow\" target=\"blank\"\u003econnect@quandl.com\u003c/a\u003e",
    "refreshed_at":"2017-11-03T21:50:44.247Z",
    "newest_available_date":"2017-11-03",
    "oldest_available_date":"1980-12-12",
    "column_names":["Date","Open","High","Low","Close","Volume","Ex-Dividend","Split Ratio","Adj. Open","Adj. High","Adj. Low","Adj. Close","Adj. Volume"],
    "frequency":"daily",
    "type":"Time Series",
    "premium":false,"
    limit":null,
    "transform":null,
    "column_index":null,
    "start_date":"2017-11-03",
    "end_date":"2017-11-03",
    "data":[["2017-11-03",174.0,174.26,171.12,172.5,58683826.0,0.0,1.0,174.0,174.26,171.12,172.5,58683826.0]],
    "collapse":null,
    "order":"asc",
    "database_id":4922}


}
  • 写回答

2条回答 默认 最新

  • dongxieyou3314 2017-11-04 23:21
    关注

    Here is the final code:

    <?php
        header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
       header("Cache-Control: post-check=0, pre-check=0", false);
       header("Pragma: no-cache");
      $url ='https://www.quandl.com/api/v3/datasets/WIKI/CNK.json?start_date=2017-11-03&end_date=2017-11-03&order=asc&transformation=rdiff&api_key=xxxx';
       $content = file_get_contents($url);
       $json = json_decode($content, true);
       $name = $json['dataset']['name'];
       $str_pos = strpos($name,"(");
       $closing_price = $json['dataset']['data'];
       echo 'Name '.substr($name,0, $str_pos).'<br/>';
       echo 'Closing price '.$closing_price[0][4].'<br/>';
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大