简体   繁体   English

如何从JSON对象数组中提取值

[英]how do I extract a value from a JSON object Array of Arrays

I am having a hard time extracting a value from the following JSON object 我很难从以下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" } } } 

I am trying to extract each item in a foreach loop within PHP Above is the var_dump of the $data[0] JSON object it demonstrates what the Array item looks like. 我试图在PHP中的foreach循环中提取每个项目。以上是$ data [0] JSON对象的var_dump,它演示了Array项目的样子。

My foreach is the following 我的前言如下

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

but it returns nothing as a result. 但结果一无所获。 Can someone explain to me how to get this from the second Array in the object? 有人可以向我解释如何从对象的第二个Array中获得此信息吗?

simply place the Index of the inner array along with the object as shown below. 只需将内部数组的索引与对象一起放置,如下所示。 This will check for the sub item for the PlatformID and return it to the screen. 这将检查PlatformID的子项并将其返回到屏幕。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM