2016-12-10 3 views
0

apiリンクhttp://steamcommunity.com/id/theorangeass/inventory/json/753/1/経由で私は蒸気から受信したJSONを解析したいですが、エコーで印刷しようとすると何も表示されません。あなたはbooleanをエコーし​​ようとしている蒸気API JSONを解析して印刷するにはどうすればいいですか? PHP

array(6) { ["success"]=> bool(true) ["rgInventory"]=> array(1) { ["922506184369981039"]=> array(5) { ["id"]=> string(18) "922506184369981039" ["classid"]=> string(10) "1254492673" ["instanceid"]=> string(10) "2070301907" ["amount"]=> string(1) "1" ["pos"]=> int(1) } } ["rgCurrency"]=> array(0) { } ["rgDescriptions"]=> array(1) { ["1254492673_2070301907"]=> array(18) { ["appid"]=> string(3) "753" ["classid"]=> string(10) "1254492673" ["instanceid"]=> string(10) "2070301907" ["icon_url"]=> string(116) "U8721VM9p9C2v1o6cKJ4qEnGqnE7IoTQgZI-VTdwyTBeimAcIowbqB-harb00cJ0fNdiCJoFB3O541FNc9ZPYXYjjL7UqfFEwOtgZKcs0eWlClqzSJn6" ["icon_url_large"]=> string(106) "U8721VM9p9C2v1o6cKJ4qEnGqnE7IoTQgZI-VTdwyTBeimAcIowbqB-harb00cJ0fNdiA54UEGOnqGQPJ9hDZHA50feEo7RMyO_GQNzkkA" ["icon_drag_url"]=> string(0) "" ["name"]=> string(4) "BEEP" ["market_name"]=> string(0) "" ["name_color"]=> string(0) "" ["background_color"]=> string(0) "" ["type"]=> string(4) "Gift" ["tradable"]=> int(0) ["marketable"]=> int(0) ["commodity"]=> int(0) ["cache_expiration"]=> string(20) "2017-01-02T00:00:00Z" ["fraudwarnings"]=> array(1) { [0]=> string(223) "This is a restricted gift which can only be redeemed in these countries: Armenia, Azerbaijan, Belarus, Georgia, Kyrgyzstan, Kazakhstan, Moldova, Republic of, Tajikistan, Turkmenistan, Uzbekistan, Ukraine, Russian Federation" } ["descriptions"]=> array(1) { [0]=> array(1) { ["value"]=> string(216) "A combination of Yoshi’s Island-style platforming with a gravity gun right out of Half-Life, BEEP is an amazing physics-platformer. Despite its friendly art style, this is a hardcore platformer in the truest sense." } } ["actions"]=> array(1) { [0]=> array(2) { ["name"]=> string(13) "View in store" ["link"]=> string(41) "http://store.steampowered.com/app/104200/" } } } } ["more"]=> bool(false) ["more_start"]=> bool(false) } 

答えて

0

:ここ はコード

$data = file_get_contents('http://steamcommunity.com/id/theorangeass/inventory/json/753/1/'); 
$json = json_decode($data, true); 

echo $json->success; 

のvar_dumpです。 trueをエコーし​​たい場合は、ifステートメントまたはswitchステートメントを実行する必要があります。 if文がおそらく最も簡単です。

echo $json->success == true ? 'TRUE' : 'FALSE'; 

配列を解析してrgInventory内のアイテムIDを取得してforeachを実行する必要があります。あなたは配列についての学習を開始する必要があります

foreach ($json['rgInventory'] as $item) { 
    echo $item['id']; 
} 

Here

+0

はどうもありがとうございました!あなたはrgInventory-> 922506184369981039-> idにある "id"をどのように印刷するか私に説明することができますか? –

+0

あなたがしようとしているのは、jsonではなく配列を解析することです。それはjsonとして受け取られ、 'json_decode'はそれを配列に変換します。私はあなたのコメントに合わせて答えを更新しました。 – spencdev

+0

ありがとうございます!感謝します! –

関連する問題