使用PHP

时间:2017-08-16 08:53:25

标签: php json

我已经阅读了关于如何使用PHP解析JSON的StackOverflow上的每个问题,但它们都没有使用我拥有的JSON。

  

array(2){[“status”] => bool(true)[“currency”] => array(30){[0] =>   array(10){[“currency”] => string(7)“EUR / AUD”[“value”] =>串(6)   “1.4925”[“change”] => string(7)“ - 0.0076”[“change_percent”] =>   string(8)“ - 0.50663”[“ask”] => string(6)“1.4926”[“bid”] =>串(6)   “1.4923”[“daily_lowest”] => string(6)“1.4873”[“daily_highest”] =>   string(6)“1.5016”[“date”] => string(19)“2017-08-16 09:46:11”   [ “型”] => string(8)“original”} [1] => array(10){[“currency”] =>   string(7)“EUR / CAD”[“value”] => string(5)“1.494”[“change”] =>   string(7)“ - 0.0032”[“change_percent”] => string(8)“ - 0.21373”   [ “问”] => string(5)“1.494”[“bid”] => string(6)“1.4939”   [ “daily_lowest”] => string(5)“1.489”[“daily_highest”] =>串(6)   “1.4986”[“date”] => string(19)“2017-08-16 09:46:11”[“type”] =>   string(8)“original”} [2] => array(10){[“currency”] =>串(7)   “EUR / CHF”[“value”] => string(6)“1.1434”[“change”] =>串(6)   “0.0024”[“change_percent”] => string(7)“0.21034”[“ask”] =>串(6)   “1.1435”[“bid”] => string(6)“1.1434”[“daily_lowest”] =>串(6)   “1.1402”[“daily_highest”] => string(6)“1.1444”[“date”] =>串(19)   “2017-08-16 09:46:11”[“type”] => string(8)“original”} [3] =>   array(10){[“currency”] => string(7)“EUR / GBP”[“value”] =>串(6)   “0.9099”[“change”] => string(7)“ - 0.0019”[“change_percent”] =>   string(8)“ - 0.20838”[“ask”] => string(4)“0.91”[“bid”] =>串(6)   “0.9099”[“daily_lowest”] => string(6)“0.9083”[“daily_highest”] =>   string(6)“0.9144”[“date”] => string(19)“2017-08-16 09:46:11”   [ “型”] => string(8)“original”} [4] => array(10){[“currency”] =>   string(7)“EUR / ILS”[“type”] => string(9)“converted”[“date”] =>   string(19)“2017-08-16 09:46:11”[“value”] => string(7)“4.24323”   [ “变化”] => string(3)“0.0”[“change_percent”] => string(3)“0.0”   [ “问”] => string(3)“0.0”[“bid”] => string(3)“0.0”[“daily_lowest”] =>   string(3)“0.0”[“daily_highest”] => string(3)“0.0”} [5] =>阵列(10)   {[“currency”] => string(7)“EUR / JPY”[“value”] => string(8)“130.1145”   [ “变化”] => string(6)“0.2425”[“change_percent”] =>串(7)   “0.18672”[“ask”] => string(7)“130.122”[“bid”] => string(7)“130.107”   [ “daily_lowest”] => string(7)“129.613”[“daily_highest”] =>串(7)   “130.405”[“date”] => string(19)“2017-08-16 09:46:11”[“type”] =>   string(8)“original”} [6] => array(10){[“currency”] =>串(7)   “EUR / NZD”[“value”] => string(6)“1.6182”[“change”] =>串(7)   “-0.0036”[“change_percent”] => string(8)“ - 0.22198”[“ask”] =>   string(6)“1.6186”[“bid”] => string(6)“1.6178”[“daily_lowest”] =>   string(6)“1.6138”[“daily_highest”] => string(6)“1.6247”[“date”] =>   string(19)“2017-08-16 09:46:11”[“type”] => string(8)“original”}   [7] =>阵列(10).............

我正在尝试使用以下代码输出每个["currency"] ["bid"]的值:

foreach($result['currency'][0]['bid'] as $item) {
    print $item['currency'][0]['bid'];
}

并尝试了100种其他变体,仍然会出现以下错误:

Warning: Illegal string offset 'currency' in getData.php on line 27
Warning: Illegal string offset 'value' in getData.php on line 27
Warning: Invalid argument supplied for foreach() in getData.php on line 27

也许有在线解析器网站可以帮助解决这个问题?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

在我看来应该是这样。

foreach($result['currency']as $item) {
    print $item['value'];
 }

因为每种货币都是0,1,2等等 在项目0,1,2中有"值"。