Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 双数组json_解码_Php_Arrays_Json_Steam - Fatal编程技术网

Php 双数组json_解码

Php 双数组json_解码,php,arrays,json,steam,Php,Arrays,Json,Steam,首先,我是新来的,英语不是我的主要语言,所以请友善点=) 我正在使用steam api atm,但我无法完成以下工作: 我可以通过描述访问json,但我也需要访问资产。第一个资产有一个assetid,即描述中的第一个项目的assetid。希望你能理解我 现在我需要将两者结合起来,这样我就可以为每一项都创建一个assetid 这是我的json: "assets":[ {"appid":"730", "contextid":"2", "asse

首先,我是新来的,英语不是我的主要语言,所以请友善点=)

我正在使用steam api atm,但我无法完成以下工作:

我可以通过描述访问json,但我也需要访问资产。第一个资产有一个assetid,即描述中的第一个项目的assetid。希望你能理解我

现在我需要将两者结合起来,这样我就可以为每一项都创建一个assetid

这是我的json:

    "assets":[
        {"appid":"730",
        "contextid":"2",
        "assetid":"9700979102",
        "classid":"310783254",
        "instanceid":"480085569",
        "amount":"1"},
        {"appid":"730",
        "contextid":"2",
        "assetid":"9700979062",
        "classid":"2050552817",
        "instanceid":"188530139",
        "amount":"1"}
    ],
    "descriptions":[
        {"appid":730,
        "classid":"310783254",
        "instanceid":"480085569",
        "currency":0,
        "background_color":"",
        "icon_url":"-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgposr-kLAtl7PvRTitD_tW1lY2EqOLmMbrfqWdY781lxOiYotWkjATk_0VuY2-lLI6VegNoYwzQ8lS-lL3qgpHvusvMyncyvic8pSGK-KHzzSg",
        "icon_url_large":"-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgposr-kLAtl7PvRTitD_tW1lY2EqOLmMbrfqWdY781lteXA54vwxlXt_EptN2nzIICXcgBoaVDQ8lTow7rvjZO86c7MznUwvHYn5nqMmxKpwUYbYpGsfXk",
        "descriptions":[],
        "tradable":1,
        "actions":[],
        "name":"Desert Eagle | Urban Rubble",
        "name_color":"D2D2D2",
        "type":"Pistole (Militärstandard)",
        "market_name":"Desert Eagle | Urban Rubble (Minimale Gebrauchsspuren)",
        "market_hash_name":"Desert Eagle | Urban Rubble (Minimal Wear)",
        "market_actions":[],
        "commodity":0,
        "market_tradable_restriction":7,
        "marketable":1,
        "tags":[]},
        {"appid":730,
        "classid":"2050552817",
        "instanceid":"188530139",
        "currency":0,
        "background_color":"",
        "icon_url":"-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpopuP1FABz7OORIQJE-dC6q5SDhfjgJ7fUqWZU7Mxkh6fEpoml2Fbj-RFuY2_xLITBewVrZ1DTrgXtw7vnjJC-tJibySA3syQk-z-DyMine1-Q",
        "icon_url_large":"-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpopuP1FABz7OORIQJE-dC6q5SDhfjgJ7fUqWZU7Mxkh9bN9J7yjRqx-BZsYzv0JtSXcgA8aVqE81Lrx-bs0cLvvsjBwHRhsiVw5S2JlhGxn1gSOUW-oNgw",
        "descriptions":[],
        "tradable":1,
        "actions":[],
        "name":"P90 | Chopper",
        "name_color":"D2D2D2",
        "type":"MP (Limitiert)",
        "market_name":"P90 | Chopper (Einsatzerprobt)",
        "market_hash_name":"P90 | Chopper (Field-Tested)",
        "market_actions":[],
        "commodity":0,
        "market_tradable_restriction":7,
        "marketable":1,"tags":[]}
还有我的php代码

$InventarUrl = "http://steamcommunity.com/inventory/".$steamID."/730/2?l=german";
$inven = file_get_contents($InventarUrl);
$invenDeco = json_decode($inven);

foreach ($invenDeco->{'assets'} as $key2 => $obj2) {
    $assetID = $obj2->assetid;
}

foreach ($invenDeco->{'descriptions'} as $key => $obj) {

    $zustand = $obj->descriptions[0]->value;

    if (strpos($zustand, "Zustand:") !== false) {
        $marketPrice = file_get_contents("http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=" . urlencode($obj->market_hash_name));
        $marketPriceDeco = json_decode($marketPrice);
        $itemName = $obj->name;
        if(strpos($obj->name, "StatTrak™")) {
            $stattrak = 1;
        } else {
            $stattrak = 0;
        }
            $ItemImageLink = $obj->icon_url;
            $ItemPrice = str_replace(",",".",$marketPriceDeco->median_price);
        }
}
我只需要知道,如何组合两个foreach数组,如何将assetid与正确的项组合

谢谢大家!

我假设“资产”和“描述”数组的大小相同

var arr = [];
for(var i = 0; i < data.assets.length; i++) {   
    var combined = new Object();
    combined.asset = data[i].asset;
    combined.description = data[i].description;
    arr.push(combined);
}
我没有将两个json数组完全组合成一个数组,但是现在每个资产和描述数据都将存储在一个对象中。所以我们有

arr[0].asset.appid == arr[0].description.appid; // TRUE

您可以使用
for
循环,而不是
foreach

for ($i = 0; $i < count($invenDeco->assets); $i++) {
    $asset       = $invenDeco->assets[$i];
    $description = $invenDeco->descriptions[$i];
    // Do something with $asset and $description
}
for($i=0;$iassets);$i++){
$asset=$invenDeco->assets[$i];
$description=$invenDeco->descriptions[$i];
//使用$asset和$description执行某些操作
}

能否同时格式化json和php代码?用这种方式很难阅读。谢谢你的回答,但我需要用PHP
for ($i = 0; $i < count($invenDeco->assets); $i++) {
    $asset       = $invenDeco->assets[$i];
    $description = $invenDeco->descriptions[$i];
    // Do something with $asset and $description
}