难以从 Edmunds API 获取样式 ID


having difficulty to get style id from edmunds api

Array ( [make] => Array ( [id] => 200000201 [name] => Nissan [niceName] => nissan ) [model] => Array ( [id] => Nissan_Pathfinder [name] => Pathfinder [niceName] => pathfinder ) [engine] => Array ( [equipmentType] => ENGINE [availability] => USED [cylinder] => 6 [size] => 3.5 [configuration] => V [fuelType] => regular unleaded [horsepower] => 260 [type] => gas [code] => VQ35DE [rpm] => Array ( [horsepower] => 6400 [torque] => 4400 ) [valve] => Array ( [gear] => double overhead camshaft ) ) [transmission] => Array ( [id] => 200405221 [name] => continuously variableA [equipmentType] => TRANSMISSION [availability] => STANDARD [automaticType] => Continuously variable [transmissionType] => AUTOMATIC [numberOfSpeeds] => continuously variable ) [drivenWheels] => front wheel drive [numOfDoors] => 4 [options] => Array ( ) [colors] => Array ( [0] => Array ( [category] => Interior [options] => Array ( [0] => Array ( [id] => 200439557 [name] => Almond Leather [equipmentType] => COLOR [availability] => USED ) ) ) [1] => Array ( [category] => Exterior [options] => Array ( [0] => Array ( [id] => 200439553 [name] => Cayenne Red Metallic [equipmentType] => COLOR [availability] => USED ) ) ) ) [manufacturerCode] => 25513 [price] => Array ( [baseMSRP] => 34850 [baseInvoice] => 31770 [deliveryCharges] => 845 [usedTmvRetail] => 22236 [usedPrivateParty] => 20769 [usedTradeIn] => 19116 [estimateTmv] => ) [categories] => Array ( [market] => Crossover [EPAClass] => Sport Utility Vehicles [vehicleSize] => Large [crossover] => Car [primaryBodyType] => SUV [vehicleStyle] => 4dr SUV [vehicleType] => SUV ) [vin] => 5N1AR2MNXDC676161 [squishVin] => 5N1AR2MNDC [years] => Array ( [0] => Array ( [id] => 100539157 [year] => 2013 [styles] => Array ( [0] => Array ( [id] => 200439517 [name] => SL 4dr SUV (3.5L 6cyl CVT) [submodel] => Array ( [body] => SUV [modelName] => Pathfinder SUV [niceName] => suv ) [trim] => SL ) ) ) ) [matchingType] => SQUISHVIN [MPG] => Array ( [highway] => 26 [city] => 20 ) ) NissanPathfinder2013

从这个数组中,我得到makemodelyear如下:

$ed_json=file_get_contents($ed_url);
$ed_array= json_decode($ed_json, true);
print_r($ed_array);
$make=$ed_array['make']['name'];
$model=$ed_array['model']['name'];
$year=$ed_array['years']['0']['year'];

echo $make;
echo $model; 
echo $year;

现在我正在做同样的事情来获取样式 ID,但我无法获得它。这是样式 ID 的代码:

$id=$ed_array['styles']['0']['id'];
echo $id;

数组多年:

[years] => Array (
    [0] => Array (
        [id] => 100539157
        [year] => 2013
        [styles] => Array (
            [0] => Array (
                [id] => 200439517
                [name] => SL 4dr SUV (3.5L 6cyl CVT)
                [submodel] => Array (
                    [body] => SUV
                    [modelName] => Pathfinder SUV
                    [niceName] => suv
                )
                [trim] => SL
            )
        )
    )
)

如您所见,[样式][0][id] 在 [年][0] 中。因此,要获得样式 id,您可以执行以下操作:

$style = $ed_array['years'][0]['styles'][0]['id'];

在您的情况下,这应该是$ed_array['years'][0]['styles'][0]['id'] .