无法从Web服务获取值

时间:2011-06-15 22:36:52

标签: php web-services json session

无法弄清楚为什么这不起作用: 只是让我空白。它应该回应“VictóriaAlmeida”

function getUserInfo() {
    $json = file_get_contents('http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Social/Login?Token=210029242357724|fd4eef8a839f24db2a9fedcd.1-100001001235070|Nro7dAY411DJRn7E8zB6MOXHjq8');
    $data = json_decode($json, TRUE);
    $userinf = array();

    foreach($data['data']['item'] as $item) {
        $userinf[] = $item;
    }

    foreach($userinf as $v) 
    {
        $_SESSION['userinfid'][] = $v['id'];
        $_SESSION['userinfnickname'][] = $v['nickname'];
        $_SESSION['userinfvisibility'][] = $v['visibility'];
        $_SESSION['userinffirstname'][] = $v['first_name'];
        $_SESSION['userinflastname'][] = $v['last_name'];
        $_SESSION['userinfgender'][] = $v['gender'];
        $_SESSION['userinfdialect'][] = $v['dialect'];
        $_SESSION['userinfstatus'][] = $v['status'];
        $_SESSION['userinfadmissiondate'][] = $v['admission_date'];
        $_SESSION['userinflastaccess'][] = $v['last_access'];
        $_SESSION['userinfusername'][] = $v['username'];
        $_SESSION['userinfpoints'][] = $v['points'];
        $_SESSION['userinfranking'][] = $v['ranking'];
        $_SESSION['userinfsessionID'][] = $v['sessionID'];
        $_SESSION['userinfpublicProfile'][] = $v['publicProfile'];
        $_SESSION['userinfemail'][] = $v['email'];
        $_SESSION['userinfmobile'][] = $v['mobile'];
        $_SESSION['userinfimageURL'][] = $v['imageURL'];
        $_SESSION['userinfclubURL'][] = $v['clubURL'];
        $_SESSION['userinfcontact'][] = $v['contacts']['contact'];
        $_SESSION['userinfcontactType'][] = $v['contacts']['contactType'];
        $_SESSION['userinfisdefault'][] = $v['contacts']['is_default'];
        $_SESSION['userinfclubId'][] = $v['clubs']['clubId'];
        $_SESSION['userinfclubName'][] = $v['clubs']['clubName'];
        $_SESSION['userinfclubLogo'][] = $v['clubs']['clubLogo'];
        $_SESSION['userinfrelationType'][] = $v['clubs']['relationType'];
        $_SESSION['userinfdateAdded'][] = $v['clubs']['dateAdded'];
    }
}

getUserInfo();
echo $_SESSION['userinfnickname'][0];

1 个答案:

答案 0 :(得分:1)

<?php
function getUserInfo() {
$json = file_get_contents('http://onleague.stormrise.pt:8031/OnLeagueRest/resources/onleague/Social/Login?Token=210029242357724|fd4eef8a839f24db2a9fedcd.1-100001001235070|Nro7dAY411DJRn7E8zB6MOXHjq8');

   $data = json_decode($json, TRUE);
  $v= $data['data'];
    $_SESSION['userinfid'][] = $v['id'];
    $_SESSION['userinfnickname'][] = $v['nickname'];
    $_SESSION['userinfvisibility'][] = $v['visibility'];
    $_SESSION['userinffirstname'][] = $v['first_name'];
    $_SESSION['userinflastname'][] = $v['last_name'];
    $_SESSION['userinfgender'][] = $v['gender'];
    $_SESSION['userinfdialect'][] = $v['dialect'];
    $_SESSION['userinfstatus'][] = $v['status'];
    $_SESSION['userinfadmissiondate'][] = $v['admission_date'];
    $_SESSION['userinflastaccess'][] = $v['last_access'];
    $_SESSION['userinfusername'][] = $v['username'];
    $_SESSION['userinfpoints'][] = $v['points'];
    $_SESSION['userinfranking'][] = $v['ranking'];
    $_SESSION['userinfsessionID'][] = $v['sessionID'];
    $_SESSION['userinfpublicProfile'][] = $v['publicProfile'];
    $_SESSION['userinfemail'][] = $v['email'];
    $_SESSION['userinfmobile'][] = $v['mobile'];
    $_SESSION['userinfimageURL'][] = $v['imageURL'];
    $_SESSION['userinfclubURL'][] = $v['clubURL'];
    $_SESSION['userinfcontact'][] = $v['contacts']['contact'];
    $_SESSION['userinfcontactType'][] = $v['contacts']['contactType'];
    $_SESSION['userinfisdefault'][] = $v['contacts']['is_default'];
    $_SESSION['userinfclubId'][] = $v['clubs']['clubId'];
    $_SESSION['userinfclubName'][] = $v['clubs']['clubName'];
    $_SESSION['userinfclubLogo'][] = $v['clubs']['clubLogo'];
    $_SESSION['userinfrelationType'][] = $v['clubs']['relationType'];
    $_SESSION['userinfdateAdded'][] = $v['clubs']['dateAdded'];
}
getUserInfo();
echo '"'.$_SESSION['userinfnickname'][0].'"'; // "Victória Almeida"
   ?>