我无法使用PHP从JSON结果中提取数据

时间:2019-11-05 11:40:38

标签: json

这是JSON查询

的结果
{
  "ACSExecution_HasError": false,
  "ACSExecutionErrorMessage": "",
  "ACSOutputResponce": {
    "ACSValueOutput": [
      {
        "ACSObjectOutput": [
          {
            "GeoID": 1329068,
            "Resolved_Street": "kolopetinitsas",
            "Resolved_Street_Num": "48",
            "Resolved_Zip": "56432",
            "Resolved_Area": "tsalonika",
            "Resolved_Long": 32.9179268,
            "Resolved_Lat": 30.6484871,
            "Resolved_GeoDataType": 1,
            "Resolved_GeoDataID": 1329068,
            "Resolved_Station_ID": "ΘΟ",
            "Resolved_Branch_ID": 1,
            "Resolved_As_Inaccesible_Area_With_Cost": 0,
            "Resolved_As_Inaccesible_Area_WithOut_Cost": 0,
            "Resolved_Confidence": 87,
            "Resolved_GeoRegionType": 2,
            "Resolved_Providence": "N.Thessalonikis",
            "Resolved_Correction": "000",
            "Resolved_Station_Descr": "Monasthriou (2310-567462)",
            "AddressID": ""
          }
        ]
      }
    ],
    "ACSTableOutput": {}
  }
}

我要提取值Resolved_Station_ID 我尝试过

$json = json_decode($response1,true);// decode the JSON feed 
echo "STATION ID=".$json->ACSValueOutput[0]->ACSObjectOutput[0]->Resolved_Station_ID;

但是它无法正常工作,我得到了这些错误

注意:尝试获取/home/deorum/public_html/pveshop.gr/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65)中非对象的属性'ACSValueOutput' :eval()在第116行上的代码

注意:尝试获取/home/deorum/public_html/pveshop.gr/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65)中非对象的属性'ACSObjectOutput' :eval()在第116行上的代码

注意:尝试获取/home/deorum/public_html/pveshop.gr/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65)中非对象的属性“ Resolved_Station_ID” :eval()在第116行上的代码

1 个答案:

答案 0 :(得分:0)

应该是:

$json["ACSOutputResponce"]["ACSValueOutput"][0]["ACSObjectOutput"][0]["Resolved_Station_ID"]

您不能将->与数组一起使用,而只能与对象一起使用。由于true中的json_decode()参数,您拥有的是一个关联数组。如果更改为json_decode(..., false),则可以通过以下方式获取它:

$json->ACSOutputResponce->ACSValueOutput[0]->ACSObjectOutput[0]->Resolved_Station_ID