打印JSON阵列 - 蒸汽网页API [英] print JSON array - steam web api

查看:142
本文介绍了打印JSON阵列 - 蒸汽网页API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩弄周围使用JSON格式蒸汽网页API。我一直在试图打印由该API提供的阵列输出。

 < PHP
    $ n = $ _GET ['身份证'];
    $关键='XXX';    $链接=的file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='$钥匙'和; steamids ='。$ ID'和;格式= JSON');
    $ profile_info = json_de code($链接);    $ json_response = json_en code($ profile_info->响应);
    打印($ json_response ['steamid']);
?>

关键显然是由蒸汽的发电机给我的钥匙取代。但是,这code段我只有返回字符 {它应该返回 76561197989628470 这是我steamid。

这是JSON格式的阵列

  {   回应:{      玩家:[         {            steamid:76561197989628470,            communityvisibilitystate:3,            profilestate:1,            personaname:Archey,            lastlogoff:1334719151,            commentpermission:1,            profileurl:http://steamcommunity.com/id/Archey6/,            阿凡达: \"http://media.steampowered.com/steamcommunity/public/images/avatars/74/745b633a08937a5cf52bb44c2bdd3552f85455d7.jpg\",            avatarmedium: \"http://media.steampowered.com/steamcommunity/public/images/avatars/74/745b633a08937a5cf52bb44c2bdd3552f85455d7_medium.jpg\",            avatarfull: \"http://media.steampowered.com/steamcommunity/public/images/avatars/74/745b633a08937a5cf52bb44c2bdd3552f85455d7_full.jpg\",            personastate:1,            primaryclanid:103582791432066081,            timecreated:1177637717,            loccountry code:CA,            locstate code:SK         }      ]   }


解决方案

你为什么那么解码编码JSON?

 < PHP
    $ n = $ _GET ['身份证'];
    $关键='XXX';    $链接=的file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='$钥匙'和; steamids ='。$ ID'和;格式= JSON');
    $ myArray的= json_de code($连接,真正的);    打印$ myArray的['响应'] ['玩家'] [0] ['steamid'];
?>

或者,如果你真的需要连接code又说:

 < PHP
    $ n = $ _GET ['身份证'];
    $关键='XXX';    $链接=的file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='$钥匙'和; steamids ='。$ ID'和;格式= JSON');
    $ profile_info = json_de code($链接);    $ json_response = json_en code($ profile_info->&响应 - GT;玩家);
    $德codeD = json_de code($ json_response,真正的);
    打印$ json_response ['steamid'];
?>

I've been toying around with the Steam Web API using JSON format. I've been trying to print the array output given by the API.

<?php
    $id = $_GET['id'];
    $key = 'xxx';

    $link = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $key . '&steamids=' . $id . '&format=json');
    $profile_info = json_decode($link);

    $json_response = json_encode($profile_info->response);
    print($json_response['steamid']);
?>

the key is obviously replace by the key given to me by Steam's generator. But this code snippet I have only returns the character { it should return 76561197989628470 which is my steamid.

These are the arrays in JSON format

{

   "response": {

      "players": [

         {

            "steamid": "76561197989628470",

            "communityvisibilitystate": 3,

            "profilestate": 1,

            "personaname": "Archey",

            "lastlogoff": 1334719151,

            "commentpermission": 1,

            "profileurl": "http://steamcommunity.com/id/Archey6/",

            "avatar": "http://media.steampowered.com/steamcommunity/public/images/avatars/74/745b633a08937a5cf52bb44c2bdd3552f85455d7.jpg",

            "avatarmedium": "http://media.steampowered.com/steamcommunity/public/images/avatars/74/745b633a08937a5cf52bb44c2bdd3552f85455d7_medium.jpg",

            "avatarfull": "http://media.steampowered.com/steamcommunity/public/images/avatars/74/745b633a08937a5cf52bb44c2bdd3552f85455d7_full.jpg",

            "personastate": 1,

            "primaryclanid": "103582791432066081",

            "timecreated": 1177637717,

            "loccountrycode": "CA",

            "locstatecode": "SK"

         }

      ]

   }

解决方案

Why are you decoding then encoding json?

<?php
    $id = $_GET['id'];
    $key = 'xxx';

    $link = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $key . '&steamids=' . $id . '&format=json');
    $myarray = json_decode($link, true);

    print $myarray['response']['players'][0]['steamid'];
?>

Or if you really need to encode again:

<?php
    $id = $_GET['id'];
    $key = 'xxx';

    $link = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $key . '&steamids=' . $id . '&format=json');
    $profile_info = json_decode($link);

    $json_response = json_encode($profile_info->response->players);
    $decoded = json_decode($json_response, true);
    print $json_response['steamid'];
?>

这篇关于打印JSON阵列 - 蒸汽网页API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆