drjmrg8766 2018-11-23 21:32
浏览 133
已采纳

Json Response数组循环

I have read pages and pages and i'm lost on how to proceed. I am trying to extract the price from a json array but the data I'm being provided seems to require i have the price first?

var_dump(json_decode($resp, true)); $Data= json_decode($resp,true);

    foreach($Data as $jsonDataKey => $jsonDataValue){
        foreach($jsonDataValue as $jsonArrayKey => $jsonArrayValue){
            echo "<hr>Price :".$jsonArrayValue['Price'];
            echo " Date:".$jsonArrayValue['Date'];
        }
    }
array) {   ["status"]=> "SUCCESS"   ["Date"]=>   array(1) {
["2018-11-23"]=>
array() {
  ["115.5"]=>
  array() {
    [0]=>
    array(46) {
      ["Price"]=> float(115.5)
      ["Date"]=> int(1543028400000)
    }
  }
  ["116.0"]=>
  array() {
    [0]=>
    array() {
      ["Price"]=> float(116.0)
      ["Date"]=> int(1543028400000)
foreach($Data as $jsonDataKey => $jsonDataValue){
    foreach($jsonDataValue as $jsonArrayKey => $jsonArrayValue){
        echo "<hr>Price :".$jsonArrayValue['Price'];
        echo " Date:".$jsonArrayValue['Date'];
    }
}

a partial snippet of the actual json:

{"symbol":"GLD","status":"SUCCESS","underlying":null,"strategy":"SINGLE","interval":null,"isDelayed":true,"isIndex":false,"interestRate":2.64581,"underlyingPrice":115.56,"volatility":29.0,"daysToExpiration":0.0,"callExpDateMap":{"2018-11-23:0":{"115.5":[{"putCall":"CALL","symbol":"GLD_112318C115.5","description":"GLD Nov 23 2018 115.5 Call (Weekly)","exchangeName":"OPR","bid":0.17,"ask":0.28,"last":0.22,"mark":0.23,"bidSize":132,"askSize":20,"lastSize":0,"highPrice":0.38,"lowPrice":0.13,"openPrice":0.0,"closePrice":0.53,"totalVolume":351,"tradeDate":null,"tradeTimeInLong":1542995987379,"quoteTimeInLong":1542995999544,"netChange":-0.31,"volatility":-999.0,"delta":1.0,"gamma":0.0,"theta":-0.008,"vega":0.0,"rho":0.003,"openInterest":2231,"timeValue":-0.05,"theoreticalOptionValue":-999.0,"theoreticalVolatility":29.0,"optionDeliverablesList":null,"strikePrice":115.5,"expirationDate":1543028400000,"daysToExpiration":0,"expirationType":"S","lastTradingDay":1542949200000,"multiplier":100.0,"settlementType":" ","deliverableNote":"","isIndexOption":null,"percentChange":-58.63,"markChange":-0.31,"markPercentChange":-57.69,"inTheMoney":true,"nonStandard":false,"mini":false}],"116.0":[{"putCall":"CALL","symbol":"GLD_112318C116","description":"GLD Nov 23 2018 116 Call (Weekly)","exchangeName":"OPR","bid":0.0,"ask":0.01,"last":0.01,"mark":0.01,"bidSize":0,"askSize":692,"lastSize":0,"highPrice":0.11,"lowPrice":0.01,"openPrice":0.0,"closePrice":0.26,"totalVolume":2167,"tradeDate":null,"tradeTimeInLong":1542995959548,"quoteTimeInLong":1542995984685,"netChange":-0.25,"volatility":0.0,"delta":0.0,"gamma":0.0,"theta":0.0,"vega":0.0,"rho":0.0,"openInterest":2786,"timeValue":0.01,"theoreticalOptionValue":0.0,"theoreticalVolatility":29.0,"optionDeliverablesList":null,"strikePrice":116.0,"expirationDate":1543028400000,"daysToExpiration":0,"expirationType":"S","lastTradingDay":1542949200000,"multiplier":100.0,"settlementType":" ","deliverableNote":"","isIndexOption":null,"percentChange":-96.21,"markChange":-0.26,"markPercentChange":-98.1,"inTheMoney":false,"nonStandard":false,"mini":false}]},"2018-11-30:7":{"115.5":[{"putCall":"CALL","symbol":"GLD_113018C115.5","description":"GLD Nov 30 2018 115.5 Call (Weekly)","exchangeName":"OPR","bid":0.77,"ask":0.79,"last":0.76,"mark":0.78,"bidSize":22,"askSize":18,"lastSize":0,"highPrice":0.89,"lowPrice":0.73,"openPrice":0.0,"closePrice":0.94,"totalVolume":217,"tradeDate":null,"tradeTimeInLong":1542995943992,"quoteTimeInLong":1542995999810,"netChange":-0.18,"volatility":9.003,"delta":0.582,"gamma":0.253,"theta":-0.042,"vega":0.067,"rho":0.015,"openInterest":755,"timeValue":0.49,"theoreticalOptionValue":0.78,"theoreticalVolatility":29.0,"optionDeliverablesList":null,"strikePrice":115.5,"expirationDate":1543633200000,"daysToExpiration":7,"expirationType":"S","lastTradingDay":1543554000000,"multiplier":100.0,"settlementType":" ","deliverableNote":"","isIndexOption":null,"percentChange":-19.17,"markChange":-0.16,"markPercentChange":-17.05,"inTheMoney":true,"nonStandard":false,"mini":false}],"116.0":[{"putCall":"CALL","symbol":"GLD_113018C116","description":"GLD Nov 30 2018 116 Call (Weekly)","exchangeName":"OPR","bid":0.52,"ask":0.55,"last":0.53,"mark":0.54,"bidSize":920,"askSize":18,"lastSize":0,"highPrice":0.63,"lowPrice":0.49,"openPrice":0.0,"closePrice":0.69,"totalVolume":1278,"tradeDate":null,"tradeTimeInLong":1542995969283,"quoteTimeInLong":1542995999922,"netChange":-0.16,"volatility":9.165,"delta":0.454,"gamma":0.252,"theta":-0.043,"vega":0.068,"rho":0.011,"openInterest":2948,"timeValue":0.53,"theoreticalOptionValue":0.535,"theoreticalVolatility":29.0,"optionDeliverablesList":null,"strikePrice":116.0,"expirationDate":1543633200000,"daysToExpiration":7,"expirationType":"S","lastTradingDay":1543554000000,"multiplier":100.0,"settlementType":" ","deliverableNote":"","isIndexOption":null,"percentChange":-23.15,"markChange":-0.15,"markPercentChange":-22.43,"inTheMoney":false,"nonStandard":false,"mini":false}]},"2018-12-07:14":{"115.5":[{"putCall":"CALL","symbol":"GLD_120718C115.5","description":"GLD Dec 7 2018 115.5 Call (Weekly)","exchangeName":"OPR","bid":1.07,"ask":1.1,"last":1.07,"mark":1.09,"bidSize":496,"askSize":22,"lastSize":0,"highPrice":1.16,"lowPrice":1.07,"openPrice":0.0,"closePrice":1.27,"totalVolume":3,"tradeDate":null,"tradeTimeInLong":1542988161634,"quoteTimeInLong":1542995999922,"netChange":-0.2,"volatility":9.532,"delta":0.569,"gamma":0.176,"theta":-0.034,"vega":0.092,"rho":0.027,"openInterest":214,"timeValue":0.8,"theoreticalOptionValue":1.085,"theoreticalVolatility":29.0,"optionDeliverablesList":null,"strikePrice":115.5,"expirationDate":1544238000000,"d

  • 写回答

2条回答 默认 最新

  • douwen1901 2018-11-23 22:13
    关注

    Looking at the data, the following code should work.

    $data = json_decode($jsonString, true);
    $history = $data['callExpDateMap'];
    foreach( $history as $date => $entry ) {
        foreach ( $entry as $key => $row ) {
            $strikePrice = $row['strikePrice'];
            echo "Date : " . $date . "
    ";
            echo "Strike price : " . $strikePrice . "
    ";
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了