PHP没有抓住JSON值

时间:2017-11-03 16:45:06

标签: php json

我正在使用TF2 Json抓取一个项目的颜色,当我尝试抓住颜色时,没有任何东西被返回。

foreach($items as $item) {
    if($item["tradable"] == 1) {

        $image_url = "http://cdn.steamcommunity.com/economy/image/";

        if($item["icon_url_large"]) {
            $image_url   = $item["icon_url_large"];
        } else {
            $image_url = $item["icon_url"];
        }

        $hash = str_replace("+", "%20", urlencode($item["market_hash_name"]));
        echo "<a href='http://steamcommunity.com/market/listings/440/$hash'>" . PHP_EOL;
        HERE > echo "<img class='item' style='border: 3px solid #". $item["tags[0].color"]; TRYING TO GRAB THIS
        echo "; border-radius: 5px;' src='http://cdn.steamcommunity.com/economy/image/$image_url' />";
        echo "</a>" . PHP_EOL;

        echo PHP_EOL;
    }
}

该代码中的其他所有工作正常,这里是json直到标签: https://pastebin.com/Gth8p7AP

这是HTML返回的内容:

<img class="item" style="border: 3px solid #; border-radius: 5px;" src="http://cdn.steamcommunity.com/economy/image/fWFc82js0fmoRAP-qOIPu5THSWqfSmTELLqcUywGkijVjZULUrsm1j-9xgEIYxQcWA_ruwdAidvjMviZBucMnuUs4IRc5jpqgwZ-euG2MWM2IAKXUvhYBPBpo1_oD3M268I2B9TloOtSeFi9t4DBN7MlY9FSX56H0R-bbNc">

1 个答案:

答案 0 :(得分:3)

看起来你要做的是:

$item["tags"][0]["color"]