JSON解码,Parse JSON响应和整数值的Undefined Index

It's so weird that I have been working on this for three days looking around the web to find a solution and making my own changes but still have no luck. I'm trying to retrieve amazon products into my website with Laravel and this great package from JoeDawson/amazon-ecs. when I execute the command from the controller like this below:

$results = Amazon::search('tv')->json();
dd($results)

I can see all the data from Amazon like this:

array:2 [
  "OperationRequest" => array:4 [
    ...
  ]
  "Items" => array:5 [
    ...
    "Item" => array:10 [
      ...
      "ItemAttributes" => array:22 [
          "Binding" => "Electronics"
          "Brand" => "LG Electronics"
          "Color" => "Black"
          "EAN" => "8806087769050"
          "EANList" => array:1 [
            "EANListElement" => "8806087769050"
          ]
          "Feature" => array:4 [
            0 => "High dynamic contrast ratio (5M:1) - richer colors, deeper blacks and greater depth of image"
            1 => "Gaming and cinema modes - dedicated features to optimise viewing experiences"
            2 => "USB AutoRun - media content from USB stick runs automatically as soon as TV is switched on"
            3 => "Detachable base - easy way to wall mount your TV and enjoy a viewing experience while saving space"
          ]
          "ItemDimensions" => array:4 [
            "Height" => "226"
            "Length" => "1560"
            "Weight" => "948"
            "Width" => "2526"
          ]
          "Label" => "LG"
          "ListPrice" => array:3 [
            "Amount" => "19999"
            "CurrencyCode" => "GBP"
            "FormattedPrice" => "£199.99"
          ]
      ]
    ]
  ]
]

Or the entire result is here: http://pastebin.com/TGFgCbAz

In my view, I have access to all the values except the values inside ListPrice, which gives back "Undefined Index"

@foreach ($results['Items']['Item'] as $amazon)
 {{ $amazon['ItemAttributes']['Title'] }} //returns true with the value
 {{ $amazon['ItemAttributes']['ListPrice']['FormattedPrice'] }} //returns Undefined index: ListPrice
@endforeach

I tried the same thing on the controller side:

foreach ($amazon_results['Items']['Item'] as $amazon) {
        print_r($amazon['ItemAttributes']['ListPrice']['FormattedPrice']);
    }

This returns the values of FormattedPrice first then throws the same error.

£199.99£34.99£194.50 Whoops, looks like something went wrong.

1/1 ErrorException in HomeController.php line 24: Undefined index: ListPrice

Why am I not able to get this value?

Hate to be the bearer of bad news, but it's simply that there is no ListPrice array for all the items. The full dump you provided had ten items. Two of them (index 7 and index 9) did not contain the ListPrice array. I'd suggest checking to make sure it exists first:

@foreach ($results['Items']['Item'] as $amazon)
 {{ $amazon['ItemAttributes']['Title'] }}
 @if (array_key_exists('ListPrice', $amazon['ItemAttributes']))
  {{ $amazon['ItemAttributes']['ListPrice']['FormattedPrice'] }}
 @else
  No list price
 @endif
@endforeach