如何从JSON对象Array of Arrays中提取值

时间:2015-01-28 20:11:18

标签: php html json

我很难从以下JSON对象中提取值

array(3) { [0]=> object(stdClass)#1 (11) { ["Group"]=> string(2) "18" ["GroupName"]=> string(8) "Wireline" ["Region"]=> string(2) "15" ["RegionName"]=> string(8) "Atlantic" ["Province"]=> string(1) "1" ["ProvinceName"]=> string(13) "New Brunswick" ["City"]=> string(2) "11" ["CityName"]=> string(10) "Campbelton" ["Site"]=> string(2) "37" ["SiteName"]=> string(16) "Campbellton PNCT" ["Year"]=> string(4) "2016" } 
           [1]=> object(stdClass)#2 (5) { ["PlatformID"]=> string(1) "1" ["PlatformTag"]=> string(6) "Access" ["Rack"]=> string(24) "23" Width 36" Depth Rack" ["RackValue"]=> string(1) "2" ["Comments"]=> string(0) "" } 
           [2]=> object(stdClass)#3 (12) { ["Rack"]=> string(31) "23" Width 36" Depth Rack Access" ["RackValue"]=> string(1) "2" ["RackComments"]=> string(0) "" ["Manufacturer"]=> string(6) "werwer" ["Name"]=> string(6) "werwer" ["Quantity"]=> string(1) "1" ["RackUnits"]=> string(1) "1" ["Power"]=> string(1) "1" ["ActivePassive"]=> string(6) "Active" ["ACDC"]=> string(2) "AC" ["ConnectivityIDs"]=> array(1) { [0]=> string(1) "2" } ["Connectivity"]=> array(1) { [0]=> string(5) "Fiber" } } } 

我试图在PHP中的foreach循环中提取每个项目上面是$ data [0] JSON对象的var_dump,它演示了Array项目的样子。

我的foreach是以下

$data = json_decode($_POST["submitdata"]);
      $Forecasts = $data[0];    
foreach($Forecasts as $Forecast){
    echo($Forecast->PlatformID);}

但结果没有返回任何结果。有人可以向我解释如何从对象中的第二个数组中获取它吗?

1 个答案:

答案 0 :(得分:0)

只需将内部数组的索引与对象一起放置,如下所示。这将检查PlatformID的子项并将其返回到屏幕。

foreach($Forecasts as $Forecast){
    echo($Forecast[1]->PlatformID);}